class Sequel::IntegerMigrator

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

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) click to toggle source

Set up all state for the migrator instance

Calls superclass method Sequel::Migrator::new
    # File lib/sequel/extensions/migration.rb
549 def initialize(db, directory, opts=OPTS)
550   super
551   @current = opts[:current] || current_migration_version
552 
553   latest_version = latest_migration_version
554   @target = if opts[:target]
555     opts[:target]
556   elsif opts[:relative]
557     @current + opts[:relative]
558   else
559     latest_version
560   end
561 
562   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
563 
564   if @target > latest_version
565     @target = latest_version
566   elsif @target < 0
567     @target = 0
568   end
569 
570   @direction = current < target ? :up : :down
571 
572   if @direction == :down && @current >= @files.length && !@allow_missing_migration_files
573     raise Migrator::Error, "Missing migration version(s) needed to migrate down to target version (current: #{current}, target: #{target})"
574   end
575 
576   @migrations = get_migrations
577 end

Public Instance Methods

is_current?() click to toggle source

The integer migrator is current if the current version is the same as the target version.

    # File lib/sequel/extensions/migration.rb
580 def is_current?
581   current_migration_version == target
582 end
run() click to toggle source

Apply all migrations on the database

    # File lib/sequel/extensions/migration.rb
585 def run
586   migrations.zip(version_numbers).each do |m, v|
587     timer = Sequel.start_timer
588     db.log_info("Begin applying migration version #{v}, direction: #{direction}")
589     checked_transaction(m) do
590       m.apply(db, direction)
591       set_migration_version(up? ? v : v-1)
592     end
593     db.log_info("Finished applying migration version #{v}, direction: #{direction}, took #{sprintf('%0.6f', Sequel.elapsed_seconds_since(timer))} seconds")
594   end
595   
596   target
597 end