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.
The current version for this migrator
The direction of the migrator, either :up or :down
The migrations used by this migrator
Set up all state for the migrator instance
# File lib/sequel/extensions/migration.rb, line 525 def initialize(db, directory, opts=OPTS) super @current = opts[:current] || current_migration_version latest_version = latest_migration_version @target = if opts[:target] opts[:target] elsif opts[:relative] @current + opts[:relative] else latest_version end if @target > latest_version @target = latest_version elsif @target < 0 @target = 0 end raise(Error, "No current version available") unless current raise(Error, "No target version available, probably because no migration files found or filenames don't follow the migration filename convention") unless target @direction = current < target ? :up : :down @migrations = get_migrations end
The integer migrator is current if the current version is the same as the target version.
# File lib/sequel/extensions/migration.rb, line 552 def is_current? current_migration_version == target end
Apply all migrations on the database
# File lib/sequel/extensions/migration.rb, line 557 def run migrations.zip(version_numbers).each do |m, v| t = Time.now db.log_info("Begin applying migration version #{v}, direction: #{direction}") checked_transaction(m) do m.apply(db, direction) set_migration_version(up? ? v : v-1) end db.log_info("Finished applying migration version #{v}, direction: #{direction}, took #{sprintf('%0.6f', Time.now - t)} seconds") end target end