Question about Rails 6 multiple databases support

47 views
Skip to first unread message

Alexandru Anca

unread,
Mar 28, 2019, 12:18:35 PM3/28/19
to Ruby on Rails: Talk
Does Rails 6 support multiple databases with different database schemas?

Rails 6 introduced support for multiple databases with this PR https://github.com/rails/rails/pull/34052
From my understanding the API designed by DHH https://github.com/rails/rails/pull/33877#issuecomment-421226095 seem to suggest that `animals` and `machines` have different structures however when I create an app with the database config as described there, when migrating, the same database structure from `base` gets copied in animals_structure.sql and machines_structure.sql .

I want to know if it's possible to have 2 databases with different structure as below

base_schema.rb
ActiveRecord::Schema.define(version: 2019) do
  create_table "create_users" do |t|
    t.string "name"
  end
end

animals_schema.rb
ActiveRecord::Schema.define(version: 2019) do
  create_table "create_dogs" do |t|
    t.string "fur_color"
  end
end

Message has been deleted

Alexandru Anca

unread,
May 31, 2019, 3:32:57 PM5/31/19
to Ruby on Rails: Talk
In case anyone is still interested in this.
According to @eileencodes , Rails 6 does support multiple databases with different structures
In order for this to work correctly you need to specify a different `migrations_path` per each database like below:

config/database.yml
development:
  primary
:
    migrations_paths
: "db/migrate/primary"
  animals
:
    migrations_paths
: "db/migrate/animals"

There is an open issue to improve documentation for this https://github.com/rails/rails/issues/36205

Reply all
Reply to author
Forward
0 new messages