class LazyMigrate::NewMigratorAdapter
Attributes
context[RW]
Public Class Methods
new()
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 15 def initialize # TODO: consider making this a method rather than an instance variable # considering how cheap it is to obtain @context = T.let( ActiveRecord::MigrationContext.instance_method(:initialize).arity == 2 ? ActiveRecord::MigrationContext.new(Rails.root.join('db', 'migrate'), ActiveRecord::SchemaMigration) : ActiveRecord::MigrationContext.new(Rails.root.join('db', 'migrate')), ActiveRecord::MigrationContext, ) end
Public Instance Methods
down(version)
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 32 def down(version) context.run(:down, version) end
migrate(version)
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 43 def migrate(version) context.up(version) end
redo(version)
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 37 def redo(version) down(version) up(version) end
rollback(version)
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 48 def rollback(version) # for some reason in https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/migration.rb#L1221 # we stop before the selected version. I have no idea why. previous_version = find_previous_version(version) if previous_version.nil? # rails excludes the given version when calling .down so we need to # just down this instead down(version) else context.down(previous_version) end end
up(version)
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 27 def up(version) context.run(:up, version) end
Protected Instance Methods
find_filename_for_migration(migration)
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 81 def find_filename_for_migration(migration) context.migrations.find { |m| m.version == migration.version }&.filename end
find_migration_tuples()
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 67 def find_migration_tuples context.migrations_status end
find_previous_version(version)
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 72 def find_previous_version(version) versions = context.migrations.map(&:version) return nil if version == versions.first previous_value(versions, version) end
last_version()
click to toggle source
# File lib/lazy_migrate/new_migrator_adapter.rb, line 86 def last_version context.migrations.last&.version end