class Sequel::TimestampMigrator

  1. lib/sequel/extensions/migration.rb
Superclass: Migrator

The migrator used if any migration file version is greater than 20000101. Stores filenames of migration files, and can figure out which migrations have not been applied and apply them, even if earlier migrations are added after later migrations. If you plan to do that, the responsibility is on you to make sure the migrations don't conflict. Part of the migration extension.


Public Class

  1. new

Public Instance

  1. applied_migrations
  2. is_current?
  3. migration_tuples
  4. run


Error = Migrator::Error  


applied_migrations [R]

Array of strings of applied migration filenames

migration_tuples [R]

Get tuples of migrations, filenames, and actions for each migration

Public Class methods

new (db, directory, opts=OPTS)

Set up all state for the migrator instance

[show source]
    # File lib/sequel/extensions/migration.rb
665 def initialize(db, directory, opts=OPTS)
666   super
667   @target = opts[:target]
668   @applied_migrations = get_applied_migrations
669   @migration_tuples = get_migration_tuples
670 end

Public Instance methods

is_current? ()

The timestamp migrator is current if there are no migrations to apply in either direction.

[show source]
    # File lib/sequel/extensions/migration.rb
674 def is_current?
675   migration_tuples.empty?
676 end
run ()

Apply all migration tuples on the database

[show source]
    # File lib/sequel/extensions/migration.rb
679 def run
680   migration_tuples.each do |m, f, direction|
681     t =
682     db.log_info("Begin applying migration #{f}, direction: #{direction}")
683     checked_transaction(m) do
684       m.apply(db, direction)
685       fi = f.downcase
686       direction == :up ? ds.insert(column=>fi) : ds.where(column=>fi).delete
687     end
688     db.log_info("Finished applying migration #{f}, direction: #{direction}, took #{sprintf('%0.6f', - t)} seconds")
689   end
690   nil
691 end