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

前端 未结 20 1409
借酒劲吻你
借酒劲吻你 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:11

    I got this to work with the following code.

    class AddInProgressToRefHighLevelStatuses < ActiveRecord::Migration
      def connection
        @connection = ActiveRecord::Base.establish_connection("sdmstore_#{Rails.env}").connection
      end
    
      def change
        add_column :ref_high_level_statuses, :is_in_progress, :boolean, :default => true
    
        @connection = ActiveRecord::Base.establish_connection("#{Rails.env}").connection
      end
    end
    

    It was necessary to set the connection back to get it to write the migration to the schema_migrations table so rake would not try to re-run the migration the next time. This assumes that you want the schema_migrations table in the default database configuration to keep track of the migrations checked into version control for the corresponding project.

    I was unable to get the down migration to work.

提交回复
热议问题