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.

Constants

Error = Migrator::Error  

Attributes

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
700 def initialize(db, directory, opts=OPTS)
701   super
702   @target = opts[:target]
703   @applied_migrations = get_applied_migrations
704   @migration_tuples = get_migration_tuples
705 end
run_single(db, path, opts=OPTS)

Apply the migration in the given file path. See Migrator.run for the available options. Additionally, this method supports the :direction option for whether to run the migration up (default) or down.

[show source]
    # File lib/sequel/extensions/migration.rb
710 def self.run_single(db, path, opts=OPTS)
711   new(db, File.dirname(path), opts).run_single(path, opts[:direction] || :up)
712 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
716 def is_current?
717   migration_tuples.empty?
718 end
run()

Apply all migration tuples on the database

[show source]
    # File lib/sequel/extensions/migration.rb
721 def run
722   migration_tuples.each do |m, f, direction|
723     apply_migration(m, f, direction)
724   end
725   nil
726 end
run_single(path, direction)

Apply single migration tuple at the given path with the given direction on the database.

[show source]
    # File lib/sequel/extensions/migration.rb
730 def run_single(path, direction)
731   migration = load_migration_file(path)
732   file_name = File.basename(path)
733   already_applied = applied_migrations.include?(file_name.downcase)
734 
735   return if direction == :up ? already_applied : !already_applied
736 
737   apply_migration(migration, file_name, direction)
738   nil
739 end