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

Set up all state for the migrator instance

[Source]

     # File lib/sequel/extensions/migration.rb, line 304
304:     def initialize(db, directory, opts={})
305:       super
306:       @target = opts[:target] || latest_migration_version
307:       @current = opts[:current] || current_migration_version
308:       @direction = current < target ? :up : :down
309:       @migrations = get_migrations
310: 
311:       raise(Error, "No current version available") unless current
312:       raise(Error, "No target version available") unless target
313:     end

Public Instance methods

Apply all migrations on the database

[Source]

     # File lib/sequel/extensions/migration.rb, line 316
316:     def run
317:       migrations.zip(version_numbers).each do |m, v|
318:         t = Time.now
319:         lv = up? ? v : v + 1
320:         db.log_info("Begin applying migration version #{lv}, direction: #{direction}")
321:         db.transaction do
322:           m.apply(db, direction)
323:           set_migration_version(v)
324:         end
325:         db.log_info("Finished applying migration version #{lv}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds")
326:       end
327:       
328:       target
329:     end

[Validate]