Class: Sequel::TimestampMigrator
- Defined in:
- lib/sequel/extensions/migration.rb
Overview
The migrator used if any migration file version appears to be a timestamp. 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.
Constant Summary collapse
Constants inherited from Migrator
Migrator::MIGRATION_FILE_PATTERN, Migrator::MIGRATION_SPLITTER, Migrator::MINIMUM_TIMESTAMP
Instance Attribute Summary collapse
-
#applied_migrations ⇒ Object
readonly
Array of strings of applied migration filenames.
-
#migration_tuples ⇒ Object
readonly
Get tuples of migrations, filenames, and actions for each migration.
Attributes inherited from Migrator
#column, #db, #directory, #ds, #files, #table, #target
Instance Method Summary collapse
-
#initialize(db, directory, opts = {}) ⇒ TimestampMigrator
constructor
Set up all state for the migrator instance.
-
#is_current? ⇒ Boolean
The timestamp migrator is current if there are no migrations to apply in either direction.
-
#run ⇒ Object
Apply all migration tuples on the database.
Methods inherited from Migrator
apply, check_current, is_current?, run
Constructor Details
#initialize(db, directory, opts = {}) ⇒ TimestampMigrator
Set up all state for the migrator instance
619 620 621 622 623 624 |
# File 'lib/sequel/extensions/migration.rb', line 619 def initialize(db, directory, opts={}) super @target = opts[:target] @applied_migrations = get_applied_migrations @migration_tuples = get_migration_tuples end |
Instance Attribute Details
#applied_migrations ⇒ Object (readonly)
Array of strings of applied migration filenames
613 614 615 |
# File 'lib/sequel/extensions/migration.rb', line 613 def applied_migrations @applied_migrations end |
#migration_tuples ⇒ Object (readonly)
Get tuples of migrations, filenames, and actions for each migration
616 617 618 |
# File 'lib/sequel/extensions/migration.rb', line 616 def migration_tuples @migration_tuples end |
Instance Method Details
#is_current? ⇒ Boolean
The timestamp migrator is current if there are no migrations to apply in either direction.
628 629 630 |
# File 'lib/sequel/extensions/migration.rb', line 628 def is_current? migration_tuples.empty? end |
#run ⇒ Object
Apply all migration tuples on the database
633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'lib/sequel/extensions/migration.rb', line 633 def run migration_tuples.each do |m, f, direction| t = Time.now db.log_info("Begin applying migration #{f}, direction: #{direction}") checked_transaction(m) do m.apply(db, direction) fi = f.downcase direction == :up ? ds.insert(column=>fi) : ds.filter(column=>fi).delete end db.log_info("Finished applying migration #{f}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds") end nil end |