Module: DbCharmer::MultiDbMigrations
- Defined in:
- lib/db_charmer/multi_db_migrations.rb
Constant Summary collapse
- @@multi_db_name =
nil
Instance Method Summary collapse
Instance Method Details
#db_magic(opts = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/db_charmer/multi_db_migrations.rb', line 21 def db_magic(opts = {}) raise ArgumentError, "No connection name - no magic!" unless opts[:connection] @@multi_db_name = opts[:connection] class << self alias_method_chain :migrate, :db_wrapper end end |
#migrate_with_db_wrapper(direction) ⇒ Object
5 6 7 |
# File 'lib/db_charmer/multi_db_migrations.rb', line 5 def migrate_with_db_wrapper(direction) on_db(@@multi_db_name) { migrate_without_db_wrapper(direction) } end |
#on_db(db_name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/db_charmer/multi_db_migrations.rb', line 9 def on_db(db_name) announce "Switching connection to #{db_name}" old_proxy = ActiveRecord::Base.db_charmer_connection_proxy ActiveRecord::Base.switch_connection_to(db_name, DbCharmer.migration_connections_should_exist?) yield ensure announce "Checking all database connections" ActiveRecord::Base.verify_active_connections! announce "Switching connection back to default" ActiveRecord::Base.switch_connection_to(old_proxy) end |