Nucc
Nucc

Reputation: 1031

Change default directory of migration files for rake db:migrate

I would like to use two independent migration logic in a project that requires two separated directories for migration files. Is there any way to change the default directory of rake db:migrate?

For instance:

DIR="db/migrations_other" rake db:migrate

Or how can you use other directory for migration files instead of db/migrate?

Upvotes: 1

Views: 1400

Answers (1)

Nucc
Nucc

Reputation: 1031

I found a way. I created a rake task for the other migration, here is the task:

namespace :db_2 do
  task :migrate => :environment do
    ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
    ActiveRecord::Migrator.migrate("db/migrate_other/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
  end
end

So now I just run

rake db_2:migrate

and it uses the other directory.

Upvotes: 1

Related Questions