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 550 def initialize(db, directory, opts=OPTS) 551 super 552 @current = opts[:current] || current_migration_version 553 554 latest_version = latest_migration_version 555 @target = if opts[:target] 556 opts[:target] 557 elsif opts[:relative] 558 @current + opts[:relative] 559 else 560 latest_version 561 end 562 563 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 564 565 if @target > latest_version 566 @target = latest_version 567 elsif @target < 0 568 @target = 0 569 end 570 571 @direction = current < target ? :up : :down 572 573 if @direction == :down && @current >= @files.length && !@allow_missing_migration_files 574 raise Migrator::Error, "Missing migration version(s) needed to migrate down to target version (current: #{current}, target: #{target})" 575 end 576 577 @migrations = get_migrations 578 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 581 def is_current? 582 current_migration_version == target 583 end
run()
Apply all migrations on the database
[show source]
# File lib/sequel/extensions/migration.rb 586 def run 587 migrations.zip(version_numbers).each do |m, v| 588 timer = Sequel.start_timer 589 db.log_info("Begin applying migration version #{v}, direction: #{direction}") 590 checked_transaction(m) do 591 m.apply(db, direction) 592 set_migration_version(up? ? v : v-1) 593 end 594 db.log_info("Finished applying migration version #{v}, direction: #{direction}, took #{sprintf('%0.6f', Sequel.elapsed_seconds_since(timer))} seconds") 595 end 596 597 target 598 end