Sha256: 5fe95d285679e8d15b73ca7f492baf261d929ac174f6d3c1362251a6070d269f

Contents?: true

Size: 1.4 KB

Versions: 20

Compression:

Stored size: 1.4 KB

Contents

require 'fileutils'
require 'active_record'
require 'ardb/runner'
require 'ardb/migration_helpers'

class Ardb::Runner::MigrateCommand

  attr_reader :migrations_path, :schema_file_path, :version, :verbose

  def initialize
    @migrations_path = Ardb.config.migrations_path
    @schema_file_path = Ardb.config.schema_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
    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

  def migrate_the_db
    if defined?(ActiveRecord::Migration::CommandRecorder)
      ActiveRecord::Migration::CommandRecorder.send(:include, Ardb::MigrationHelpers::RecorderMixin)
    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

    require 'active_record/schema_dumper'
    FileUtils.mkdir_p File.dirname(@schema_file_path)
    File.open(@schema_file_path, "w:utf-8") do |file|
      ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
    end
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ardb-0.20.0 lib/ardb/runner/migrate_command.rb
ardb-0.19.0 lib/ardb/runner/migrate_command.rb
ardb-0.18.0 lib/ardb/runner/migrate_command.rb
ardb-0.17.0 lib/ardb/runner/migrate_command.rb
ardb-0.16.0 lib/ardb/runner/migrate_command.rb
ardb-0.15.0 lib/ardb/runner/migrate_command.rb
ardb-0.14.0 lib/ardb/runner/migrate_command.rb
ardb-0.13.0 lib/ardb/runner/migrate_command.rb
ardb-0.12.0 lib/ardb/runner/migrate_command.rb
ardb-0.11.0 lib/ardb/runner/migrate_command.rb
ardb-0.10.0 lib/ardb/runner/migrate_command.rb
ardb-0.9.0 lib/ardb/runner/migrate_command.rb
ardb-0.8.0 lib/ardb/runner/migrate_command.rb
ardb-0.7.0 lib/ardb/runner/migrate_command.rb
ardb-0.6.0 lib/ardb/runner/migrate_command.rb
ardb-0.5.0 lib/ardb/runner/migrate_command.rb
ardb-0.4.1 lib/ardb/runner/migrate_command.rb
ardb-0.4.0 lib/ardb/runner/migrate_command.rb
ardb-0.3.0 lib/ardb/runner/migrate_command.rb
ardb-0.2.0 lib/ardb/runner/migrate_command.rb