The migrator used if any migration file version is greater than 20000101. Stores filenames of migration files, and can figure out which migrations have not been applied and apply them, even if earlier migrations are added after later migrations. If you plan to do that, the responsibility is on you to make sure the migrations don’t conflict. Part of the migration
extension.
Methods
Public Class
Public Instance
Constants
Error | = | Migrator::Error |
Attributes
applied_migrations | [R] |
|
migration_tuples | [R] |
Get tuples of migrations, filenames, and actions for each migration |
Public Class methods
Set up all state for the migrator instance
# File lib/sequel/extensions/migration.rb 689 def initialize(db, directory, opts=OPTS) 690 super 691 @target = opts[:target] 692 @applied_migrations = get_applied_migrations 693 @migration_tuples = get_migration_tuples 694 end
Apply the migration in the given file path. See Migrator.run
for the available options. Additionally, this method supports the :direction option for whether to run the migration up (default) or down.
# File lib/sequel/extensions/migration.rb 699 def self.run_single(db, path, opts=OPTS) 700 new(db, File.dirname(path), opts).run_single(path, opts[:direction] || :up) 701 end
Public Instance methods
The timestamp migrator is current if there are no migrations to apply in either direction.
# File lib/sequel/extensions/migration.rb 705 def is_current? 706 migration_tuples.empty? 707 end
Apply all migration tuples on the database
# File lib/sequel/extensions/migration.rb 710 def run 711 migration_tuples.each do |m, f, direction| 712 apply_migration(m, f, direction) 713 end 714 nil 715 end
Apply single migration tuple at the given path with the given direction on the database.
# File lib/sequel/extensions/migration.rb 719 def run_single(path, direction) 720 migration = load_migration_file(path) 721 file_name = File.basename(path) 722 already_applied = applied_migrations.include?(file_name.downcase) 723 724 return if direction == :up ? already_applied : !already_applied 725 726 apply_migration(migration, file_name, direction) 727 nil 728 end