Class: Ardb::Runner::MigrateCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/ardb/runner/migrate_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMigrateCommand

Returns a new instance of MigrateCommand.



10
11
12
13
14
15
# File 'lib/ardb/runner/migrate_command.rb', line 10

def initialize
  @adapter = Ardb::Adapter.send(Ardb.config.db.adapter)
  @migrations_path = Ardb.config.migrations_path
  @version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
  @verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
end

Instance Attribute Details

#migrations_pathObject (readonly)

Returns the value of attribute migrations_path.



8
9
10
# File 'lib/ardb/runner/migrate_command.rb', line 8

def migrations_path
  @migrations_path
end

#verboseObject (readonly)

Returns the value of attribute verbose.



8
9
10
# File 'lib/ardb/runner/migrate_command.rb', line 8

def verbose
  @verbose
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/ardb/runner/migrate_command.rb', line 8

def version
  @version
end

Instance Method Details

#migrate_the_dbObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ardb/runner/migrate_command.rb', line 30

def migrate_the_db
  if defined?(ActiveRecord::Migration::CommandRecorder)
    ActiveRecord::Migration::CommandRecorder.class_eval do
      include Ardb::MigrationHelpers::RecorderMixin
    end
  end

  ActiveRecord::Migrator.migrations_path = @migrations_path
  ActiveRecord::Migration.verbose = @verbose
  ActiveRecord::Migrator.migrate(@migrations_path, @version) do |migration|
    ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
  end

  @adapter.dump_schema
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ardb/runner/migrate_command.rb', line 17

def run
  begin
    Ardb.init
    migrate_the_db
  rescue Ardb::Runner::CmdError => e
    raise e
  rescue Exception => e
    $stderr.puts e
    $stderr.puts "error migrating #{Ardb.config.db.database.inspect} database"
    raise Ardb::Runner::CmdFail
  end
end