Sha256: b068342a1b9e975f73df3fd6b320782e1f3e5d0fcc16d31a14119c5eda32e5bd

Contents?: true

Size: 942 Bytes

Versions: 17

Compression:

Stored size: 942 Bytes

Contents

module DataMigrate
  # Helper class to getting access to db schema
  # to allow data/schema combiation tasks
  class SchemaMigration
    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, kind: :schema }}
      )
    end

    def self.run(direction, migration_paths, version)
      ActiveRecord::Migrator.run(direction, migration_paths, version)
    end

    def self.sort_migrations(set1, set2 = nil)
      migrations = set1 + (set2 || [])
      migrations.sort {|a, b|  sort_string(a) <=> sort_string(b)}
    end

    def self.migrations_paths
      Rails.application.config.paths["db/migrate"].to_a
    end

    def self.sort_string(migration)
      "#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}"
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
data_migrate-6.2.0 lib/data_migrate/schema_migration.rb
data_migrate-6.1.0 lib/data_migrate/schema_migration.rb
data_migrate-6.0.7 lib/data_migrate/schema_migration.rb
data_migrate-6.0.6 lib/data_migrate/schema_migration.rb
data_migrate-6.0.5 lib/data_migrate/schema_migration.rb
data_migrate-6.0.4.beta lib/data_migrate/schema_migration.rb
data_migrate-6.0.3.beta lib/data_migrate/schema_migration.rb
data_migrate-6.0.1.beta lib/data_migrate/schema_migration.rb
data_migrate-6.0.0.beta lib/data_migrate/schema_migration.rb
data_migrate-5.3.2 lib/data_migrate/schema_migration.rb
data_migrate-5.3.1 lib/data_migrate/schema_migration.rb
data_migrate-5.3.0 lib/data_migrate/schema_migration.rb
data_migrate-5.2.0 lib/data_migrate/schema_migration.rb
data_migrate-5.1.0 lib/data_migrate/schema_migration.rb
data_migrate-5.0.2 lib/data_migrate/schema_migration.rb
data_migrate-5.0.0 lib/data_migrate/schema_migration.rb
data_migrate-4.0.0 lib/data_migrate/schema_migration.rb