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.
Constants
Error | = | Migrator::Error |
Attributes
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 |
Public Class methods
new(db, directory, opts=OPTS)
Set up all state for the migrator instance
[show source]
# File lib/sequel/extensions/migration.rb 538 def initialize(db, directory, opts=OPTS) 539 super 540 @current = opts[:current] || current_migration_version 541 542 latest_version = latest_migration_version 543 @target = if opts[:target] 544 opts[:target] 545 elsif opts[:relative] 546 @current + opts[:relative] 547 else 548 latest_version 549 end 550 551 raise(Error, "No target and/or latest version available, probably because no migration files found or filenames don't follow the migration filename convention") unless target && latest_version 552 553 if @target > latest_version 554 @target = latest_version 555 elsif @target < 0 556 @target = 0 557 end 558 559 @direction = current < target ? :up : :down 560 561 if @direction == :down && @current >= @files.length && !@allow_missing_migration_files 562 raise Migrator::Error, "Missing migration version(s) needed to migrate down to target version (current: #{current}, target: #{target})" 563 end 564 565 @migrations = get_migrations 566 end
Public Instance methods
is_current?()
The integer migrator is current if the current version is the same as the target version.
[show source]
# File lib/sequel/extensions/migration.rb 569 def is_current? 570 current_migration_version == target 571 end
run()
Apply all migrations on the database
[show source]
# File lib/sequel/extensions/migration.rb 574 def run 575 migrations.zip(version_numbers).each do |m, v| 576 timer = Sequel.start_timer 577 db.log_info("Begin applying migration version #{v}, direction: #{direction}") 578 checked_transaction(m) do 579 m.apply(db, direction) 580 set_migration_version(up? ? v : v-1) 581 end 582 db.log_info("Finished applying migration version #{v}, direction: #{direction}, took #{sprintf('%0.6f', Sequel.elapsed_seconds_since(timer))} seconds") 583 end 584 585 target 586 end