Class: Sequel::TimestampMigrator

Inherits:
Object
  • Object
show all
Includes:
TimestampMigratorLogger
Defined in:
lib/sequel/timestamp_migrator_undo_extension.rb

Defined Under Namespace

Modules: TimestampMigratorLogger

Instance Method Summary collapse

Methods included from TimestampMigratorLogger

#run

Instance Method Details

#undo(version) ⇒ Object

Rollback a migration



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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