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 304 304: def initialize(db, directory, opts={}) 305: super 306: @target = opts[:target] || latest_migration_version 307: @current = opts[:current] || current_migration_version 308: 309: raise(Error, "No current version available") unless current 310: raise(Error, "No target version available") unless target 311: 312: @direction = current < target ? :up : :down 313: @migrations = get_migrations 314: end
Apply all migrations on the database
# File lib/sequel/extensions/migration.rb, line 317 317: def run 318: migrations.zip(version_numbers).each do |m, v| 319: t = Time.now 320: lv = up? ? v : v + 1 321: db.log_info("Begin applying migration version #{lv}, direction: #{direction}") 322: db.transaction do 323: m.apply(db, direction) 324: set_migration_version(v) 325: end 326: db.log_info("Finished applying migration version #{lv}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds") 327: end 328: 329: target 330: end