class DataMigrate::SchemaMigration

Helper class to getting access to db schema to allow data/schema combiation tasks

Helper class to getting access to db schema to allow data/schema combiation tasks

Helper class to getting access to db schema to allow data/schema combiation tasks

Public Class Methods

migrations_paths() click to toggle source
# File lib/data_migrate/schema_migration.rb, line 23
def self.migrations_paths
  Rails.application.config.paths["db/migrate"].to_a
end
pending_schema_migrations() click to toggle source
# File lib/data_migrate/schema_migration.rb, line 5
def self.pending_schema_migrations
  all_migrations = DataMigrate::DataMigrator.migrations(migrations_paths)
  sort_migrations(
    ActiveRecord::Migrator.new(:up, all_migrations).
    pending_migrations.
    map {|m| { version: m.version, name: m.name, kind: :schema }}
  )
end
run(direction, migration_paths, version) click to toggle source
# File lib/data_migrate/schema_migration.rb, line 14
def self.run(direction, migration_paths, version)
  ActiveRecord::Migrator.run(direction, migration_paths, version)
end
sort_migrations(set1, set2 = nil) click to toggle source
# File lib/data_migrate/schema_migration.rb, line 18
def self.sort_migrations(set1, set2 = nil)
  migrations = set1 + (set2 || [])
  migrations.sort {|a, b|  sort_string(a) <=> sort_string(b)}
end
sort_string(migration) click to toggle source
# File lib/data_migrate/schema_migration.rb, line 27
def self.sort_string(migration)
  "#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}"
end