Using Rails Migration on different database than standard “production” or “development”

前端 未结 20 1426
借酒劲吻你
借酒劲吻你 2020-11-29 18:18

I have a rails project running that defines the standard production:, :development and :test DB-connections in config/database.yml

In addition I have a quiz_developm

20条回答
  •  青春惊慌失措
    2020-11-29 19:03

    A bit late, but I was dealing with this problem today and I came up with this custom rake task:

    namespace :db do
      desc "Apply db tasks in custom databases, for example  rake db:alter[db:migrate,test-es] applies db:migrate on the database defined as test-es in databases.yml"
      task :alter, [:task,:database] => [:environment] do |t, args|
        require 'activerecord'
        puts "Applying #{args.task} on #{args.database}"
        ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[args.database])
        Rake::Task[args.task].invoke
      end
    end
    

提交回复
热议问题