我嘗試使用下列方式我的一些遷移的輔助數據庫連接:多個數據庫連接:schema_migrations在錯誤的數據庫中查找
# app/models/staging/migration.rb
class Staging::Migration < ActiveRecord::Migration
def self.connection
ActiveRecord::Base.establish_connection(:staging_db).connection
end
end
# db/migrate/<timestamp>_create_foo.rb
class CreateFoo < Staging::Migration
....
end
在我的database.yml的staging_db連接配置。
當我運行rake db:migrate時,在staging_db模式中正確創建了表foo,並且在RAILS_ENV = development連接中創建了表schema_migrations。然而分貝:遷移的報告以下錯誤(這失敗的後續遷移):
表「staging_db.schema_migrations」 不存在
有沒有辦法告訴分期::遷移看對於當前RAILS_ENV連接中的schema_migrations表?
順便說一句,我知道staging_db然後不RAILS_ENV意識到的事實。這對我來說很好,因爲每個服務器的環境都是通過單獨的database.yml進行配置的,這不在我的repo中。