Class: Sequel::IntegerMigrator
- Defined in:
- lib/sequel/extensions/migration.rb
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 collapse
Constants inherited from Migrator
Migrator::MIGRATION_FILE_PATTERN, Migrator::MIGRATION_SPLITTER, Migrator::MINIMUM_TIMESTAMP
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
The current version for this migrator.
-
#direction ⇒ Object
readonly
The direction of the migrator, either :up or :down.
-
#migrations ⇒ Object
readonly
The migrations used by this migrator.
Attributes inherited from Migrator
#column, #db, #directory, #ds, #files, #table, #target
Instance Method Summary collapse
-
#initialize(db, directory, opts = OPTS) ⇒ IntegerMigrator
constructor
Set up all state for the migrator instance.
-
#is_current? ⇒ Boolean
The integer migrator is current if the current version is the same as the target version.
-
#run ⇒ Object
Apply all migrations on the database.
Methods inherited from Migrator
apply, check_current, is_current?, migrator_class, run
Constructor Details
#initialize(db, directory, opts = OPTS) ⇒ IntegerMigrator
Set up all state for the migrator instance
521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/sequel/extensions/migration.rb', line 521 def initialize(db, directory, opts=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
#current ⇒ Object (readonly)
The current version for this migrator
512 513 514 |
# File 'lib/sequel/extensions/migration.rb', line 512 def current @current end |
#direction ⇒ Object (readonly)
The direction of the migrator, either :up or :down
515 516 517 |
# File 'lib/sequel/extensions/migration.rb', line 515 def direction @direction end |
#migrations ⇒ Object (readonly)
The migrations used by this migrator
518 519 520 |
# File 'lib/sequel/extensions/migration.rb', line 518 def migrations @migrations end |
Instance Method Details
#is_current? ⇒ Boolean
The integer migrator is current if the current version is the same as the target version.
534 535 536 |
# File 'lib/sequel/extensions/migration.rb', line 534 def is_current? current_migration_version == target end |
#run ⇒ Object
Apply all migrations on the database
539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/sequel/extensions/migration.rb', line 539 def run migrations.zip(version_numbers).each do |m, v| t = Time.now db.log_info("Begin applying migration version #{v}, direction: #{direction}") checked_transaction(m) do m.apply(db, direction) set_migration_version(up? ? v : v-1) end db.log_info("Finished applying migration version #{v}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds") end target end |