Class: DataMigrate::SchemaMigration
- Inherits:
-
Object
- Object
- DataMigrate::SchemaMigration
- Defined in:
- lib/data_migrate/schema_migration.rb
Overview
Helper class to getting access to db schema to allow data/schema combiation tasks
Class Method Summary collapse
- .migrations_paths ⇒ Object
- .pending_schema_migrations ⇒ Object
- .run(direction, migration_paths, version) ⇒ Object
- .sort_migrations(set1, set2 = nil) ⇒ Object
- .sort_string(migration) ⇒ Object
Class Method Details
.migrations_paths ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/data_migrate/schema_migration.rb', line 25 def self.migrations_paths spec_name = DataMigrate.config.spec_name if spec_name && Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version) ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: spec_name).migrations_paths elsif spec_name && Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version) ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: spec_name).migrations_paths else Rails.application.config.paths["db/migrate"].to_a end end |
.pending_schema_migrations ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/data_migrate/schema_migration.rb', line 7 def self.pending_schema_migrations all_migrations = DataMigrate::MigrationContext.new(migrations_paths).migrations sort_migrations( ActiveRecord::Migrator.new(:up, all_migrations, ActiveRecord::Base.connection.schema_migration). pending_migrations. map {|m| { version: m.version, kind: :schema }} ) end |
.run(direction, migration_paths, version) ⇒ Object
16 17 18 |
# File 'lib/data_migrate/schema_migration.rb', line 16 def self.run(direction, migration_paths, version) ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::Base.connection.schema_migration).run(direction, version) end |
.sort_migrations(set1, set2 = nil) ⇒ Object
20 21 22 23 |
# File 'lib/data_migrate/schema_migration.rb', line 20 def self.sort_migrations(set1, set2 = nil) migrations = set1 + (set2 || []) migrations.sort {|a, b| sort_string(a) <=> sort_string(b)} end |
.sort_string(migration) ⇒ Object
36 37 38 |
# File 'lib/data_migrate/schema_migration.rb', line 36 def self.sort_string(migration) "#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}" end |