Module: ActiveRecord::TestDatabases

Defined in:
activerecord/lib/active_record/test_databases.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.create_and_load_schema(i, env_name:) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'activerecord/lib/active_record/test_databases.rb', line 11

def self.create_and_load_schema(i, env_name:)
  old, ENV["VERBOSE"] = ENV["VERBOSE"], "false"

  ActiveRecord::Base.configurations.configs_for(env_name: env_name).each do |db_config|
    database = "#{db_config.database}-#{i}"

    db_config_copy = ActiveRecord::DatabaseConfigurations::HashConfig.new(
      env_name,
      db_config.spec_name,
      db_config.configuration_hash.merge(database: database)
    )

    ActiveRecord::Tasks::DatabaseTasks.reconstruct_from_schema(db_config_copy, ActiveRecord::Base.schema_format, nil)
  end
ensure
  ActiveRecord::Base.establish_connection(ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_sym)
  ENV["VERBOSE"] = old
end