Class: DataMigrate::DataMigrator

Inherits:
ActiveRecord::Migrator
  • Object
show all
Defined in:
lib/data_migrate/data_migrator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_data_schema_tableObject



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_versionObject



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_pathString

Provides the full migrations_path filepath

Returns:

  • (String)


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

Parameters:

  • filename (String)

Returns:

  • (MatchData)


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_pathsObject



14
15
16
# File 'lib/data_migrate/data_migrator.rb', line 14

def migrations_paths
  [DataMigrate.config.data_migrations_path]
end

.migrations_statusObject



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

Returns:

  • (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_migratedObject



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