| 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.
| Error | = | Migrator::Error |
| 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 |
Set up all state for the migrator instance
# File lib/sequel/extensions/migration.rb, line 516
516: def initialize(db, directory, opts=OPTS)
517: super
518: @current = opts[:current] || current_migration_version
519: raise(Error, "No current version available") unless current
520:
521: latest_version = latest_migration_version
522:
523: @target = if opts[:target]
524: opts[:target]
525: elsif opts[:relative]
526: @current + opts[:relative]
527: else
528: latest_version
529: end
530:
531: raise(Error, "No target version available, probably because no migration files found or filenames don't follow the migration filename convention") unless target
532:
533: if @target > latest_version
534: @target = latest_version
535: elsif @target < 0
536: @target = 0
537: end
538:
539: @direction = current < target ? :up : :down
540: @migrations = get_migrations
541: end
The integer migrator is current if the current version is the same as the target version.
# File lib/sequel/extensions/migration.rb, line 544
544: def is_current?
545: current_migration_version == target
546: end
Apply all migrations on the database
# File lib/sequel/extensions/migration.rb, line 549
549: def run
550: migrations.zip(version_numbers).each do |m, v|
551: timer = Sequel.start_timer
552: db.log_info("Begin applying migration version #{v}, direction: #{direction}")
553: checked_transaction(m) do
554: m.apply(db, direction)
555: set_migration_version(up? ? v : v-1)
556: end
557: db.log_info("Finished applying migration version #{v}, direction: #{direction}, took #{sprintf('%0.6f', Sequel.elapsed_seconds_since(timer))} seconds")
558: end
559:
560: target
561: end