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

Constructor Details

#initialize(direction, migrations, target_version = nil) ⇒ DataMigrator

Returns a new instance of DataMigrator.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/data_migrate/data_migrator.rb', line 16

def initialize(direction, migrations, target_version = nil)
  @direction         = direction
  @target_version    = target_version
  @migrated_versions = nil
  @migrations        = migrations

  validate(@migrations)

  DataMigrate::DataSchemaMigration.create_table
  ActiveRecord::InternalMetadata.create_table
end

Class Method Details

.assure_data_schema_tableObject



12
13
14
# File 'lib/data_migrate/data_migrator.rb', line 12

def self.assure_data_schema_table
  DataMigrate::DataSchemaMigration.create_table
end

.current_versionObject



34
35
36
# File 'lib/data_migrate/data_migrator.rb', line 34

def current_version
  DataMigrate::MigrationContext.new(migrations_paths).current_version
end

.full_migrations_pathString

Provides the full migrations_path filepath

Returns:

  • (String)


53
54
55
# File 'lib/data_migrate/data_migrator.rb', line 53

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)


43
44
45
# File 'lib/data_migrate/data_migrator.rb', line 43

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



62
63
64
65
# File 'lib/data_migrate/data_migrator.rb', line 62

def migrations(_migrations_paths)
  #DataMigrate::MigrationContext.new(migrations_paths).migrations
  DataMigrate::MigrationContext.new(_migrations_paths).migrations
end

.migrations_pathsObject



8
9
10
# File 'lib/data_migrate/data_migrator.rb', line 8

def self.migrations_paths
  [DataMigrate.config.data_migrations_path]
end

.migrations_statusObject



57
58
59
# File 'lib/data_migrate/data_migrator.rb', line 57

def migrations_status
  DataMigrate::MigrationContext.new(migrations_paths).migrations_status
end

.needs_migration?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/data_migrate/data_migrator.rb', line 47

def needs_migration?
  DataMigrate::DatabaseTasks.pending_migrations.count.positive?
end

.rollback(migrations_path, steps) ⇒ Object



72
73
74
# File 'lib/data_migrate/data_migrator.rb', line 72

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



68
69
70
# File 'lib/data_migrate/data_migrator.rb', line 68

def run(direction, migration_paths, version)
  DataMigrate::MigrationContext.new(migration_paths).run(direction, version)
end

Instance Method Details

#load_migratedObject



28
29
30
31
# File 'lib/data_migrate/data_migrator.rb', line 28

def load_migrated
  @migrated_versions =
    DataMigrate::DataSchemaMigration.normalized_versions.map(&:to_i).sort
end