class NonschemaMigrator::MigrationContext
Public Class Methods
new(migrations_paths, data_migration)
click to toggle source
# File lib/nonschema_migrator.rb, line 24 def initialize(migrations_paths, data_migration) # super(migrations_paths, data_migration) @migrations_paths = migrations_paths @schema_migration = NonschemaMigrator::NonSchemaMigration end
Public Instance Methods
down(target_version = nil) { |m| ... }
click to toggle source
# File lib/nonschema_migrator.rb, line 102 def down(target_version = nil) selected_migrations = if block_given? migrations.select { |m| yield m } else migrations end new_migrator(:down, selected_migrations, target_version).migrate end
get_all_versions()
click to toggle source
these methods are copied from ActiveRecord::Migrator replaced:
1.) ActiveRecord::NonSchemaMigration with @schema_migration 2.) ActiveRecord::Migrator.new with new_migrator
# File lib/nonschema_migrator.rb, line 43 def get_all_versions if @schema_migration.table_exists? @schema_migration.all_versions.map(&:to_i) else [] end end
migrations_status()
click to toggle source
# File lib/nonschema_migrator.rb, line 51 def migrations_status db_list = @schema_migration.normalized_versions file_list = migration_files.map do |file| version, name, scope = parse_migration_filename(file) raise IllegalMigrationNameError.new(file) unless version version = @schema_migration.normalize_migration_number(version) status = db_list.delete(version) ? "up" : "down" [status, version, (name + scope).humanize] end.compact db_list.map! do |version| ["up", version, "********** NO FILE **********"] end (db_list + file_list).sort_by { |_, version, _| version } end
move(direction, steps)
click to toggle source
# File lib/nonschema_migrator.rb, line 73 def move(direction, steps) migrator = new_migrator(direction, migrations, schema_migration) if current_version != 0 && !migrator.current_migration raise UnknownMigrationVersionError.new(current_version) end start_index = if current_version == 0 0 else migrator.migrations.index(migrator.current_migration) end finish = migrator.migrations[start_index + steps] version = finish ? finish.version : 0 send(direction, version) end
new_migrator(*args)
click to toggle source
# File lib/nonschema_migrator.rb, line 32 def new_migrator(*args) result = NonschemaMigrator.new(*args) result.migration_context = self result end
rollback(steps)
click to toggle source
# File lib/nonschema_migrator.rb, line 69 def rollback(steps) move(:down, steps) end
up(target_version = nil) { |m| ... }
click to toggle source
# File lib/nonschema_migrator.rb, line 92 def up(target_version = nil) selected_migrations = if block_given? migrations.select { |m| yield m } else migrations end new_migrator(:up, selected_migrations, target_version).migrate end