class Apartment::Adapters::Mysql2SchemaAdapter

def connect_to_new(database)


Set schema current_database to new db
def connect_to_new(database)
  return reset if database.nil?
  Apartment.connection.execute "use #{environmentify(database)}"
rescue ActiveRecord::StatementInvalid
  Apartment::Database.reset
  raise DatabaseNotFound, "Cannot find database #{environmentify(database)}"
end

def initialize(config)

def initialize(config)
  @default_database = config[:database]
  super
end

def process_excluded_model(model)

def process_excluded_model(model)
  model.constantize.tap do |klass|
    # some models (such as delayed_job) seem to load and cache their column names before this,
    # so would never get the default prefix, so reset first
    klass.reset_column_information
    # Ensure that if a schema *was* set, we override
    table_name = klass.table_name.split('.', 2).last
    klass.table_name = "#{default_database}.#{table_name}"
  end
end

def process_excluded_models


Set the table_name to always use the default database for excluded models
def process_excluded_models
  Apartment.excluded_models.each{ |model| process_excluded_model(model) }
end

def reset


Reset current_database to the default_database
def reset
  Apartment.connection.execute "use #{default_database}"
end