Question about Rails 6 multiple databases support

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about Rails 6 multiple databases support

Alexandru Anca
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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a788e34d-2959-4111-afa1-868f1ebd3f7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Question about Rails 6 multiple databases support

Alexandru Anca
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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/944c17f9-8bd1-4c38-bf96-a0bd229ed131%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Question about Rails 6 multiple databases support

Alexandru Anca
In reply to this post by Alexandru Anca
In case anyone is interested in this,

According to @eileencodes it is possible to have multiple database with different structures in Rails 6. For this to work correctly the `migrations_paths` needs to be set for each database as below:

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

Alexandru

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c19cb229-14fd-4370-bc88-b62d609e4fd5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.