class Sequel::TimestampMigrator

Public Instance Methods

undo(version) click to toggle source

Rollback a migration

# File lib/sequel/timestamp_migrator_undo_extension.rb, line 9
def undo(version)
  path = files.find { |file| migration_version_from_file(get_filename(file)) == version }
  error!("Migration #{version} does not exist in the filesystem") unless path

  filename = get_filename(path)
  error!("Migration #{version} is not applied") unless applied_migrations.include?(filename)

  migration = get_migration(path)

  time = Time.now
  db.log_info("Undoing migration #{filename}")

  checked_transaction(migration) do
    migration.apply(db, :down)
    ds.filter(column => filename).delete
  end

  elapsed = format("%<time>0.6f", time: Time.now - time)
  db.log_info("Finished undoing migration #{filename}, took #{elapsed} seconds")
end

Private Instance Methods

error!(message) click to toggle source
# File lib/sequel/timestamp_migrator_undo_extension.rb, line 61
def error!(message)
  raise Sequel::Migrator::Error, message
end
get_filename(path) click to toggle source
# File lib/sequel/timestamp_migrator_undo_extension.rb, line 57
def get_filename(path)
  File.basename(path).downcase
end
get_migration(path) click to toggle source
# File lib/sequel/timestamp_migrator_undo_extension.rb, line 48
def get_migration(path)
  migration = load_migration_file(path)

  return migration if Gem::Version.new(Sequel.version) >= Gem::Version.new("5.6")
  # :nocov:
  Migration.descendants.last
  # :nocov:
end