lib/multiverse/patches.rb in multiverse-0.0.1 vs lib/multiverse/patches.rb in multiverse-0.0.2
- old
+ new
@@ -1,38 +1,46 @@
module Multiverse
module DatabaseTasks
def each_current_configuration(environment)
- if Multiverse.db
- environments = ["#{Multiverse.db}_#{environment}"]
- environments << "#{Multiverse.db}_test" if environment == "development"
- self.migrations_paths = Multiverse.migrate_path
- self.db_dir = Multiverse.db_dir
- else
- environments = [environment]
- environments << "test" if environment == "development"
- end
+ environments = [Multiverse.env(environment)]
+ environments << Multiverse.env("test") if environment == "development"
+ self.migrations_paths = Multiverse.migrate_path
+ self.db_dir = Multiverse.db_dir
+
configurations = ActiveRecord::Base.configurations.values_at(*environments)
configurations.compact.each do |configuration|
yield configuration unless configuration['database'].blank?
end
end
end
- module Migration
- def connection
- @connection || Multiverse.record_class.connection
+ module Migrator
+ def initialize(*_)
+ puts "Migrator#initialize"
+ # ActiveRecord::Migration#initialize calls
+ # ActiveRecord::SchemaMigration.create_table
+ # ActiveRecord::InternalMetadata.create_table
+ # which both inherit from ActiveRecord::Base
+ #
+ # We need to change this for migrations
+ # but not for db:schema:load (messes up multiverse test env otherwise)
+ ActiveRecord::SchemaMigration.singleton_class.prepend(Multiverse::Connection)
+ ActiveRecord::InternalMetadata.singleton_class.prepend(Multiverse::Connection)
+ super
end
+ end
+ module Migration
# TODO don't checkout main connection at all
def exec_migration(_, direction)
Multiverse.record_class.connection_pool.with_connection do |conn|
super(conn, direction)
end
end
end
- module SchemaMigration
+ module Connection
def connection
Multiverse.record_class.connection
end
end