Class: DataMigrate::DataMigrator
- Inherits:
-
ActiveRecord::Migrator
- Object
- ActiveRecord::Migrator
- DataMigrate::DataMigrator
- Defined in:
- lib/data_migrate/data_migrator.rb
Class Method Summary collapse
- .create_data_schema_table ⇒ Object
- .current_version ⇒ Object
-
.full_migrations_path ⇒ String
Provides the full migrations_path filepath.
-
.match(filename) ⇒ MatchData
Compares the given filename with what we expect data migration filenames to be, eg the “20091231235959_some_name.rb” pattern.
-
.migrations(_migrations_paths) ⇒ Object
TODO: this was added to be backward compatible, need to re-evaluate.
- .migrations_paths ⇒ Object
- .migrations_status ⇒ Object
- .needs_migration? ⇒ Boolean
- .rollback(migrations_path, steps) ⇒ Object
-
.run(direction, migration_paths, version) ⇒ Object
TODO: this was added to be backward compatible, need to re-evaluate.
Instance Method Summary collapse
Class Method Details
.create_data_schema_table ⇒ Object
18 19 20 |
# File 'lib/data_migrate/data_migrator.rb', line 18 def create_data_schema_table DataMigrate::RailsHelper.data_schema_migration.create_table end |
.current_version ⇒ Object
22 23 24 |
# File 'lib/data_migrate/data_migrator.rb', line 22 def current_version DataMigrate::MigrationContext.new(migrations_paths).current_version end |
.full_migrations_path ⇒ String
Provides the full migrations_path filepath
41 42 43 |
# File 'lib/data_migrate/data_migrator.rb', line 41 def full_migrations_path File.join(Rails.root, *migrations_paths.split(File::SEPARATOR)) end |
.match(filename) ⇒ MatchData
Compares the given filename with what we expect data migration filenames to be, eg the “20091231235959_some_name.rb” pattern
31 32 33 |
# File 'lib/data_migrate/data_migrator.rb', line 31 def match(filename) /(\d{14})_(.+)\.rb$/.match(filename) end |
.migrations(_migrations_paths) ⇒ Object
TODO: this was added to be backward compatible, need to re-evaluate
50 51 52 53 |
# File 'lib/data_migrate/data_migrator.rb', line 50 def migrations(_migrations_paths) #DataMigrate::MigrationContext.new(migrations_paths).migrations DataMigrate::MigrationContext.new(_migrations_paths).migrations end |
.migrations_paths ⇒ Object
14 15 16 |
# File 'lib/data_migrate/data_migrator.rb', line 14 def migrations_paths [DataMigrate.config.data_migrations_path] end |
.migrations_status ⇒ Object
45 46 47 |
# File 'lib/data_migrate/data_migrator.rb', line 45 def migrations_status DataMigrate::MigrationContext.new(migrations_paths).migrations_status end |
.needs_migration? ⇒ Boolean
35 36 37 |
# File 'lib/data_migrate/data_migrator.rb', line 35 def needs_migration? DataMigrate::DatabaseTasks.pending_migrations.count.positive? end |
.rollback(migrations_path, steps) ⇒ Object
64 65 66 |
# File 'lib/data_migrate/data_migrator.rb', line 64 def rollback(migrations_path, steps) DataMigrate::MigrationContext.new(migrations_path).rollback(steps) end |
.run(direction, migration_paths, version) ⇒ Object
TODO: this was added to be backward compatible, need to re-evaluate
56 57 58 59 60 61 62 |
# File 'lib/data_migrate/data_migrator.rb', line 56 def run(direction, migration_paths, version) # Ensure all Active Record model cache is reset for each data migration # As recommended in: https://github.com/rails/rails/blob/da21c2e9812e5eb0698fba4a9aa38632fc004432/activerecord/lib/active_record/migration.rb#L467-L470 ActiveRecord::Base.descendants.each(&:reset_column_information) DataMigrate::MigrationContext.new(migration_paths).run(direction, version) end |
Instance Method Details
#load_migrated ⇒ Object
8 9 10 11 |
# File 'lib/data_migrate/data_migrator.rb', line 8 def load_migrated @migrated_versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions.map(&:to_i).sort end |