Sha256: b3298dc58ec753808705beeba673bc0f197ffd13a0cbc815b0860ee9016ae628

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

module Multiverse
  module DatabaseTasks
    def each_current_configuration(environment)
      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 Migrator
    def initialize(*_)
      # ActiveRecord::Migration#initialize calls
      # ActiveRecord::SchemaMigration.create_table and
      # ActiveRecord::InternalMetadata.create_table
      # which both inherit from ActiveRecord::Base
      #
      # We need to change this for migrations
      # but not for db:schema:load, as this
      # will mess up the Multiverse test environment
      ActiveRecord::SchemaMigration.singleton_class.prepend(Multiverse::Connection)
      ActiveRecord::InternalMetadata.singleton_class.prepend(Multiverse::Connection)
      super
    end
  end

  module Connection
    def connection
      Multiverse.record_class.connection
    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 SchemaDumper
    def dump(connection = ActiveRecord::Base.connection, stream = STDOUT, config = ActiveRecord::Base)
      new(Multiverse.record_class.connection, generate_options(Multiverse.record_class)).dump(stream)
      stream
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
multiverse-0.1.2 lib/multiverse/patches.rb
multiverse-0.1.1 lib/multiverse/patches.rb
multiverse-0.1.0 lib/multiverse/patches.rb
multiverse-0.0.3 lib/multiverse/patches.rb