Class | Sequel::IntegerMigrator |
In: |
lib/sequel/extensions/migration.rb
|
Parent: | Migrator |
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.
DEFAULT_SCHEMA_COLUMN | = | :version |
DEFAULT_SCHEMA_TABLE | = | :schema_info |
Error | = | Migrator::Error |
current | [R] | The current version for this migrator |
direction | [R] | The direction of the migrator, either :up or :down |
migrations | [R] | The migrations used by this migrator |
Set up all state for the migrator instance
# File lib/sequel/extensions/migration.rb, line 505 505: def initialize(db, directory, opts=OPTS) 506: super 507: @target = opts[:target] || latest_migration_version 508: @current = opts[:current] || current_migration_version 509: 510: raise(Error, "No current version available") unless current 511: raise(Error, "No target version available, probably because no migration files found or filenames don't follow the migration filename convention") unless target 512: 513: @direction = current < target ? :up : :down 514: @migrations = get_migrations 515: end
The integer migrator is current if the current version is the same as the target version.
# File lib/sequel/extensions/migration.rb, line 518 518: def is_current? 519: current_migration_version == target 520: end
Apply all migrations on the database
# File lib/sequel/extensions/migration.rb, line 523 523: def run 524: migrations.zip(version_numbers).each do |m, v| 525: t = Time.now 526: lv = up? ? v : v + 1 527: db.log_info("Begin applying migration version #{lv}, direction: #{direction}") 528: checked_transaction(m) do 529: m.apply(db, direction) 530: set_migration_version(v) 531: end 532: db.log_info("Finished applying migration version #{lv}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds") 533: end 534: 535: target 536: end