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 523 523: def initialize(db, directory, opts=OPTS) 524: super 525: @current = opts[:current] || current_migration_version 526: latest_version = latest_migration_version 527: 528: @target = if opts[:target] 529: opts[:target] 530: elsif opts[:relative] 531: @current + opts[:relative] 532: else 533: latest_version 534: end 535: 536: if @target > latest_version 537: @target = latest_version 538: elsif @target < 0 539: @target = 0 540: end 541: 542: raise(Error, "No current version available") unless current 543: raise(Error, "No target version available, probably because no migration files found or filenames don't follow the migration filename convention") unless target 544: 545: @direction = current < target ? :up : :down 546: @migrations = get_migrations 547: end
The integer migrator is current if the current version is the same as the target version.
# File lib/sequel/extensions/migration.rb, line 550 550: def is_current? 551: current_migration_version == target 552: end
Apply all migrations on the database
# File lib/sequel/extensions/migration.rb, line 555 555: def run 556: migrations.zip(version_numbers).each do |m, v| 557: t = Time.now 558: db.log_info("Begin applying migration version #{v}, direction: #{direction}") 559: checked_transaction(m) do 560: m.apply(db, direction) 561: set_migration_version(up? ? v : v-1) 562: end 563: db.log_info("Finished applying migration version #{v}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds") 564: end 565: 566: target 567: end