Class: Sequel::IntegerMigrator
Overview
The default migrator, recommended in most cases. Uses a simple incrementing version number starting with 1, where missing or duplicate migration file versions are not allowed. Part of the migration extension.
Constant Summary
- DEFAULT_SCHEMA_COLUMN =
:version- DEFAULT_SCHEMA_TABLE =
:schema_info- Error =
Migrator::Error
Constants inherited from Migrator
Migrator::MIGRATION_FILE_PATTERN, Migrator::MIGRATION_SPLITTER, Migrator::MINIMUM_TIMESTAMP
Instance Attribute Summary (collapse)
-
- (Object) current
readonly
The current version for this migrator.
-
- (Object) direction
readonly
The direction of the migrator, either :up or :down.
-
- (Object) migrations
readonly
The migrations used by this migrator.
Attributes inherited from Migrator
#column, #db, #directory, #ds, #files, #table, #target
Instance Method Summary (collapse)
-
- (IntegerMigrator) initialize(db, directory, opts = {})
constructor
Set up all state for the migrator instance.
-
- (Object) run
Apply all migrations on the database.
Methods inherited from Migrator
Constructor Details
- (IntegerMigrator) initialize(db, directory, opts = {})
Set up all state for the migrator instance
457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/sequel/extensions/migration.rb', line 457 def initialize(db, directory, opts={}) super @target = opts[:target] || latest_migration_version @current = opts[:current] || current_migration_version raise(Error, "No current version available") unless current raise(Error, "No target version available, probably because no migration files found or filenames don't follow the migration filename convention") unless target @direction = current < target ? :up : :down @migrations = get_migrations end |
Instance Attribute Details
- (Object) current (readonly)
The current version for this migrator
448 449 450 |
# File 'lib/sequel/extensions/migration.rb', line 448 def current @current end |
- (Object) direction (readonly)
The direction of the migrator, either :up or :down
451 452 453 |
# File 'lib/sequel/extensions/migration.rb', line 451 def direction @direction end |
- (Object) migrations (readonly)
The migrations used by this migrator
454 455 456 |
# File 'lib/sequel/extensions/migration.rb', line 454 def migrations @migrations end |
Instance Method Details
- (Object) run
Apply all migrations on the database
470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/sequel/extensions/migration.rb', line 470 def run migrations.zip(version_numbers).each do |m, v| t = Time.now lv = up? ? v : v + 1 db.log_info("Begin applying migration version #{lv}, direction: #{direction}") checked_transaction(m) do m.apply(db, direction) set_migration_version(v) end db.log_info("Finished applying migration version #{lv}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds") end target end |