class NondestructiveMigrator::MigrationContext

Public Class Methods

new(migrations_paths) click to toggle source
Calls superclass method
# File lib/nondestructive_migrator.rb, line 16
def initialize(migrations_paths)
  super(migrations_paths)
  @schema_migration = NondestructiveMigrator::SchemaMigration
end

Public Instance Methods

down(target_version = nil) { |m| ... } click to toggle source
# File lib/nondestructive_migrator.rb, line 87
def down(target_version = nil)
  selected_migrations = if block_given?
    migrations.select { |m| yield m }
  else
    migrations
  end

  new_migrator(:down, selected_migrations, target_version).migrate
end
get_all_versions() click to toggle source

these methods are copied from ActiveRecord::Migrator replaced:

1.) ActiveRecord::SchemaMigration with @schema_migration
2.) ActiveRecord::Migrator.new with new_migrator
# File lib/nondestructive_migrator.rb, line 32
def get_all_versions
  if @schema_migration.table_exists?
    @schema_migration.all_versions.map(&:to_i)
  else
    []
  end
end
migrations_status() click to toggle source
# File lib/nondestructive_migrator.rb, line 40
def migrations_status
  db_list = @schema_migration.normalized_versions

  file_list = migration_files.map do |file|
    version, name, scope = parse_migration_filename(file)
    raise IllegalMigrationNameError.new(file) unless version
    version = @schema_migration.normalize_migration_number(version)
    status = db_list.delete(version) ? "up" : "down"
    [status, version, (name + scope).humanize]
  end.compact

  db_list.map! do |version|
    ["up", version, "********** NO FILE **********"]
  end

  (db_list + file_list).sort_by { |_, version, _| version }
end
move(direction, steps) click to toggle source
# File lib/nondestructive_migrator.rb, line 58
def move(direction, steps)
  migrator = new_migrator(direction, migrations)

  if current_version != 0 && !migrator.current_migration
    raise UnknownMigrationVersionError.new(current_version)
  end

  start_index =
    if current_version == 0
      0
    else
      migrator.migrations.index(migrator.current_migration)
    end

  finish = migrator.migrations[start_index + steps]
  version = finish ? finish.version : 0
  send(direction, version)
end
new_migrator(*args) click to toggle source
# File lib/nondestructive_migrator.rb, line 21
def new_migrator(*args)
  result = NondestructiveMigrator.new(*args)
  result.migration_context = self
  result
end
up(target_version = nil) { |m| ... } click to toggle source
# File lib/nondestructive_migrator.rb, line 77
def up(target_version = nil)
  selected_migrations = if block_given?
    migrations.select { |m| yield m }
  else
    migrations
  end

  new_migrator(:up, selected_migrations, target_version).migrate
end