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 421 421: def initialize(db, directory, opts={}) 422: super 423: @target = opts[:target] || latest_migration_version 424: @current = opts[:current] || current_migration_version 425: 426: raise(Error, "No current version available") unless current 427: raise(Error, "No target version available") unless target 428: 429: @direction = current < target ? :up : :down 430: @migrations = get_migrations 431: end
Apply all migrations on the database
# File lib/sequel/extensions/migration.rb, line 434 434: def run 435: migrations.zip(version_numbers).each do |m, v| 436: t = Time.now 437: lv = up? ? v : v + 1 438: db.log_info("Begin applying migration version #{lv}, direction: #{direction}") 439: db.transaction do 440: m.apply(db, direction) 441: set_migration_version(v) 442: end 443: db.log_info("Finished applying migration version #{lv}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds") 444: end 445: 446: target 447: end