class Sequel::IntegerMigrator

  1. lib/sequel/extensions/migration.rb
Superclass: 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.

Methods

Public Class

  1. new

Public Instance

  1. current
  2. direction
  3. is_current?
  4. migrations
  5. run

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
525 def initialize(db, directory, opts=OPTS)
526   super
527   @current = opts[:current] || current_migration_version
528 
529   latest_version = latest_migration_version
530   @target = if opts[:target]
531     opts[:target]
532   elsif opts[:relative]
533     @current + opts[:relative]
534   else
535     latest_version
536   end
537 
538   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
539 
540   if @target > latest_version
541     @target = latest_version
542   elsif @target < 0
543     @target = 0
544   end
545 
546   @direction = current < target ? :up : :down
547 
548   if @direction == :down && @current >= @files.length && !@allow_missing_migration_files
549     raise Migrator::Error, "Missing migration version(s) needed to migrate down to target version (current: #{current}, target: #{target})"
550   end
551 
552   @migrations = get_migrations
553 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
556 def is_current?
557   current_migration_version == target
558 end
run()

Apply all migrations on the database

[show source]
    # File lib/sequel/extensions/migration.rb
561 def run
562   migrations.zip(version_numbers).each do |m, v|
563     timer = Sequel.start_timer
564     db.log_info("Begin applying migration version #{v}, direction: #{direction}")
565     checked_transaction(m) do
566       m.apply(db, direction)
567       set_migration_version(up? ? v : v-1)
568     end
569     db.log_info("Finished applying migration version #{v}, direction: #{direction}, took #{sprintf('%0.6f', Sequel.elapsed_seconds_since(timer))} seconds")
570   end
571   
572   target
573 end