0

We are using rails app and have lot of data in live tables. So we are starting to archive the data into different database and have minimal required data in live tables. But only issue I am facing is how to handle schema changes. Is there any way to run migrations on both live db and archival db on rake db:migrate?

Any suggestion on how to handle this kind of situation, where its necessary to keep schema of both db in sync.

Thanks, GG

GG.
  • 2,835
  • 5
  • 27
  • 34
  • Seams same to: http://stackoverflow.com/questions/1404620/using-rails-migration-on-different-database-than-standard-production-or-devel – griffon vulture Oct 17 '13 at 11:44
  • this talks about running migration on DB_2 while database.yml have DB_1 and DB_2. In my case I want to run migrations on both DB_1 and DB2. – GG. Oct 17 '13 at 11:59
  • found http://excid3.com/blog/rails-activerecord-multiple-databases-and-migrations/ which looks like a good idea – GG. Oct 17 '13 at 12:02

1 Answers1

2
desc "Migrate the database through scripts in db/migrate."
namespace :db do
  task :migrate do
    Rake::Task["db:migrate_db1"].invoke
    Rake::Task["db:migrate_db2"].invoke
  end

  task :migrate_db1 do
    ActiveRecord::Base.establish_connection DB1_CONF
    ActiveRecord::Migrator.migrate("db/migrate/db1/")
  end

  task :migrate_db2 do
    ActiveRecord::Base.establish_connection DB2_CONF
    ActiveRecord::Migrator.migrate("db/migrate/db2/")
  end
end
griffon vulture
  • 6,594
  • 6
  • 36
  • 57
  • Thats what http://excid3.com/blog/rails-activerecord-multiple-databases-and-migrations/ says. – GG. Oct 17 '13 at 12:21