Module: Appfuel::Db::MigrationsInitializer

Defined in:
lib/appfuel/storage/db/migration_initializer.rb

Class Method Summary collapse

Class Method Details

.call(settings = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/appfuel/storage/db/migration_initializer.rb', line 7

def self.call(settings = {})
  root_name = settings[:root_name] || Appfuel.default_app_name
  container = Appfuel.app_container(root_name)

  config    = container[:config]
  root_path = container[:root_path]
  env = container[:env]
  db_path = config[:db][:path]
  migrations_paths = config[:db][:migrations_path]
  db_config = config[:db][:main]

  db_tasks = settings.fetch(:db_tasks) {
    ActiveRecord::Tasks::DatabaseTasks
  }

  db_migrator = settings.fetch(:db_migrator) {
    ActiveRecord::Migrator
  }

  active_record_base = settings.fetch(:active_record_base) {
    ActiveRecord::Base
  }

  active_record_base.configurations = {env => db_config}

  db_tasks.root = root_path
  db_tasks.env = env
  db_tasks.db_dir = db_path
  db_tasks.migrations_paths = migrations_paths
  db_tasks.database_configuration = db_config

  db_migrator.migrations_paths = migrations_paths
end