Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveRecord::Migration - Referencing a table in another schema
    text
    copied!<p>I'm using Ruby and PostgreSQL and have created 3 distinct DB schemas: billing (for billing related data), customer (for customer related data) and edocs (for electronic documents related data). I'm not using Rails so I have a stand-alone migration code like this:</p> <pre><code>#migrate.rb if ARGV[0] =~ /VERSION=\d+/ version = ARGV[0].split('=')[1].to_i else version = nil end ActiveRecord::Base.default_timezone = :utc @logger = Logger.new $stderr ActiveRecord::Base.logger = @logger ActiveSupport::LogSubscriber.colorize_logging = false @config = YAML.load_file(File.join(File.dirname(__FILE__), 'database.yml')) ActiveRecord::Base.establish_connection(@config["edocs"]) ActiveRecord::Migrator.migrate(".", version) </code></pre> <p>I have already realized that I probably have to create a different directories to contain the migration for the different schemas, and changing connection info for each migrate.rb.</p> <p>But I'm not sure how I'm going to make a table reference another table that is in another schema. For example:</p> <pre><code>class CreateBillingEventsTable &lt; ActiveRecord::Migration def self.up create_table :billing_events do |t| t.references :customer, :null =&gt; false t.references :service_type, :null =&gt; false t.timestamps end change_table :billing_events do |t| t.index [:customer_id, :created_at] end end def self.down remove_index :billing_events, :column =&gt; [:customer_id, :created_at] drop_table :billing_events end end </code></pre> <p>In the above example, "customer" and "billing_events" are in different schemas. How can I code that?</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload