Class: Databasion::Migrate

Inherits:
Object
  • Object
show all
Defined in:
lib/databasion/migrate.rb

Constant Summary collapse

@@config =
nil

Class Method Summary collapse

Class Method Details

.config=(config) ⇒ Object



7
8
9
# File 'lib/databasion/migrate.rb', line 7

def self.config=(config)
  @@config = config
end

.run(opts) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/databasion/migrate.rb', line 11

def self.run(opts)
  require 'migration_helpers/init'

  files = Dir["%s/%s/*.yml" % [opts[:env], @@config['output']['yaml_path']]]
  Databasion::BuildMigration.run(files, @@config, opts)

  Databasion.set_ar_logger
  Databasion::LOGGER.info "Migrating..."

  YAML.load_file('config/database.%s.yml' % opts[:env]).each do |config|
    ActiveRecord::Base.establish_connection(config[1])
    path = opts[:env] + "/" + @@config['output']['migrations']['path'] + "/" + config[0]
    ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
    ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
  end
end