lib/ardb/runner/migrate_command.rb in ardb-0.24.0 vs lib/ardb/runner/migrate_command.rb in ardb-0.25.0
- old
+ new
@@ -1,47 +1,28 @@
require 'fileutils'
require 'active_record'
require 'ardb/runner'
-require 'ardb/migration_helpers'
class Ardb::Runner::MigrateCommand
- attr_reader :migrations_path, :version, :verbose
-
- def initialize
+ def initialize(out_io = nil, err_io = nil)
+ @out_io = out_io || $stdout
+ @err_io = err_io || $stderr
@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
def run
begin
Ardb.init
- migrate_the_db
+ @adapter.migrate_db
+ @adapter.dump_schema
rescue Ardb::Runner::CmdError => e
raise e
- rescue Exception => e
- $stderr.puts "error migrating #{Ardb.config.db.database.inspect} database"
- $stderr.puts e
- $stderr.puts e.backtrace
+ rescue StandardError => e
+ @err_io.puts "error migrating #{Ardb.config.db.database.inspect} database"
+ @err_io.puts e
+ @err_io.puts e.backtrace
raise Ardb::Runner::CmdFail
end
- end
-
- 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
end