0

In my rails app, I reference multiple databases. Using connection_ninja I tell models where to point, but how do I do the same for migrations?

RAILS_ENV doesn't work since specific migrations need to point to specific DBs

Thanks in advanced, Justin

UPDATE--------------

I discovered establish_connection (basis for conn_ninja & connected to other dbs) is not honored by ActiveRecord::Migration even though the method is part of ActiveRecord::Base.

Any ideas on how to hack around this?

Justin
  • 631
  • 2
  • 7
  • 13

2 Answers2

0

A bit of an old one, but I struggled with this recently and finally discovered not just a hack, but an actual solution.

The trick is to use a Model connection instead of modifying the ActiveRecord::Base connection which will cause issues after the migration when schema_migrations are updated.

Take a look here: https://stackoverflow.com/a/34292909/2499227

Community
  • 1
  • 1
MTarantini
  • 939
  • 7
  • 11
0

ActiveRecord::Migration just uses ActiveRecord::Base so you should hypothetically be able to put use_connection_ninja(:group) in your migration

ErsatzRyan
  • 3,033
  • 1
  • 26
  • 30