class NondestructiveMigrator
Public Class Methods
context(path)
click to toggle source
# File lib/nondestructive_migrator.rb, line 99 def context(path) NondestructiveMigrator::MigrationContext.new(path) end
get_all_versions(connection = ActiveRecord::Base.connection)
click to toggle source
# File lib/nondestructive_migrator.rb, line 151 def get_all_versions(connection = ActiveRecord::Base.connection) if connection.table_exists?(schema_migrations_table_name) ActiveRecord::DataMigration.all.map { |x| x.version.to_i }.sort else [] end end
migrate(path)
click to toggle source
# File lib/nondestructive_migrator.rb, line 109 def migrate(path) context(path).migrate() end
migrations_path()
click to toggle source
# File lib/nondestructive_migrator.rb, line 139 def migrations_path MIGRATIONS_PATH end
new_migrator(path, *args)
click to toggle source
# File lib/nondestructive_migrator.rb, line 103 def new_migrator(path, *args) result = self.new(*args) result.migration_context=context(path) result end
run(direction, path, target_version)
click to toggle source
# File lib/nondestructive_migrator.rb, line 113 def run(direction, path, target_version) new_migrator(path, direction, context(path).migrations, target_version).run end
schema_migrations_table_name()
click to toggle source
# File lib/nondestructive_migrator.rb, line 143 def schema_migrations_table_name 'data_migrations' end
Public Instance Methods
load_migrated()
click to toggle source
# File lib/nondestructive_migrator.rb, line 122 def load_migrated @migrated_versions = Set.new(@migration_context.get_all_versions) end
migration_context=(context)
click to toggle source
# File lib/nondestructive_migrator.rb, line 118 def migration_context=(context) @migration_context = context end
record_version_state_after_migrating(version)
click to toggle source
# File lib/nondestructive_migrator.rb, line 127 def record_version_state_after_migrating(version) if down? migrated.delete(version) ActiveRecord::DataMigration.where(:version => version.to_s).delete_all else migrated << version ActiveRecord::DataMigration.create!(:version => version.to_s) end end