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
553 def initialize(db, directory, opts=OPTS)
554   super
555   @current = opts[:current] || current_migration_version
556 
557   latest_version = latest_migration_version
558   @target = if opts[:target]
559     opts[:target]
560   elsif opts[:relative]
561     @current + opts[:relative]
562   else
563     latest_version
564   end
565 
566   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
567 
568   if @target > latest_version
569     @target = latest_version
570   elsif @target < 0
571     @target = 0
572   end
573 
574   @direction = current < target ? :up : :down
575 
576   if @direction == :down && @current >= @files.length && !@allow_missing_migration_files
577     raise Migrator::Error, "Missing migration version(s) needed to migrate down to target version (current: #{current}, target: #{target})"
578   end
579 
580   @migrations = get_migrations
581 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
584 def is_current?
585   current_migration_version == target
586 end
run()

Apply all migrations on the database

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