Class | Sequel::IntegerMigrator
In: | lib/sequel/extensions/migration.rb
Parent: | 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

new run

### Constants

DEFAULT_SCHEMA_COLUMN | = | :version
DEFAULT_SCHEMA_TABLE | = | :schema_info
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={})

Set up all state for the migrator instance

[Source]

         # File lib/sequel/extensions/migration.rb, line 422
    422:     def initialize(db, directory, opts={})
    423:       super
    424:       @target = opts[:target] || latest_migration_version
    425:       @current = opts[:current] || current_migration_version
    426:
    427:       raise(Error, "No current version available") unless current
    428:       raise(Error, "No target version available, probably because no migration files found or filenames don't follow the migration filename convention") unless target
    429:
    430:       @direction = current < target ? :up : :down
    431:       @migrations = get_migrations
    432:     end

### Public Instance methods

run()

Apply all migrations on the database

[Source]

         # File lib/sequel/extensions/migration.rb, line 435
    435:     def run
    436:       migrations.zip(version_numbers).each do |m, v|
    437:         t = Time.now
    438:         lv = up? ? v : v + 1
    439:         db.log_info("Begin applying migration version #{lv}, direction: #{direction}")
    440:         db.transaction do
    441:           m.apply(db, direction)
    442:           set_migration_version(v)
    443:         end
    444:         db.log_info("Finished applying migration version #{lv}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds")
    445:       end
    446:
    447:       target
    448:     end

[Validate]