class NonschemaMigrator

Public Class Methods

context(path) click to toggle source
# File lib/nonschema_migrator.rb, line 114
def context(path)
  NonschemaMigrator::MigrationContext.new(path, ActiveRecord::DataMigration)
end
get_all_versions(connection = ActiveRecord::Base.connection) click to toggle source
# File lib/nonschema_migrator.rb, line 170
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/nonschema_migrator.rb, line 124
def migrate(path)
  context(path).migrate()
end
migrations_path() click to toggle source
# File lib/nonschema_migrator.rb, line 158
def migrations_path
  MIGRATIONS_PATH
end
new(direction, migrations, no_op, target_version = nil) click to toggle source

This class related to data migration. Used in rake tasks (rake data:)

# File lib/nonschema_migrator.rb, line 5
def initialize(direction, migrations, no_op, target_version = nil)
  @direction         = direction
  @target_version    = target_version
  @migrated_versions = nil
  @migrations        = migrations

  validate(@migrations)

  ActiveRecord::InternalMetadata.create_table
end
new_migrator(path, *args) click to toggle source
# File lib/nonschema_migrator.rb, line 118
def new_migrator(path, *args)
  result = self.new(*args)
  result.migration_context=context(path)
  result
end
rollback(path, steps = 1) click to toggle source
# File lib/nonschema_migrator.rb, line 128
def rollback(path, steps = 1)
  context(path).rollback(steps)
end
run(direction, path, target_version) click to toggle source
# File lib/nonschema_migrator.rb, line 132
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/nonschema_migrator.rb, line 162
def schema_migrations_table_name
  'data_migrations'
end

Public Instance Methods

load_migrated() click to toggle source
# File lib/nonschema_migrator.rb, line 141
def load_migrated
  @migrated_versions = Set.new(@migration_context.get_all_versions)
end
migration_context=(context) click to toggle source
# File lib/nonschema_migrator.rb, line 137
def migration_context=(context)
  @migration_context = context
end
record_version_state_after_migrating(version) click to toggle source
# File lib/nonschema_migrator.rb, line 146
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