Rails 6 Multiple Databases Clarification
scottrobertson opened this issue ยท 4 comments
Hey
We have been using the multiverse gem for a long time to manage multiple databases, but with an upgrade to Rails 6, we are moving to use their built-in setup.
Previously, we had the following:
DatabaseCleaner[:active_record].strategy = :deletion
DatabaseCleaner[:active_record, { connection: :provider_data_test }].strategy = :deletion
With the following in the Model's
establish_connection :"provider_data_#{Rails.env}"
The new way of doing it is by having the following in database.yml:
test:
primary:
<<: *default
provider_data:
<<: *provider_data_default
And this in the models:
connects_to database: { writing: :provider_data, reading: :provider_data }
How should Database cleaner be setup for this? It's clearing the primary db, but it's not clearing the secondary dbs. I have tried this for example:
DatabaseCleaner[:active_record, { connection: :provider_data }].strategy = :deletion
Will ask this in the AR repo actually.
@scottrobertson Thanks for opening this issue! I went ahead and transferred it to the right repository.
I believe you can do it like this:
DatabaseCleaner[:active_record, { connection: :primary }].strategy = :deletion
DatabaseCleaner[:active_record, { connection: :provider_data }].strategy = :deletion
If that doesn't work, let us know!
@etagwerker thank you ๐
Yeah that worked :) figured it out between closing the old issue, and when i was supposed to open the new one ha.
@scottrobertson Great! I realize that the documentation could be better (https://github.com/DatabaseCleaner/database_cleaner-active_record#adapter-configuration-options), so if you think of an improvement for our README, I'd be happy to review it ๐