Class: Dekiru::DataMigration::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/dekiru/data_migration/migration.rb

Overview

Base class for data migration with testable method separation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/dekiru/data_migration/migration.rb', line 7

def self.run(options = {})
  migration = new
  title = migration.title

  Operator.execute(title, options) do
    migration.instance_variable_set(:@operator_context, self)
    migration.migrate
  end
end

Instance Method Details

#migrateObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dekiru/data_migration/migration.rb', line 21

def migrate
  targets = migration_targets

  log "Target count: #{targets.count}"
  confirm?

  find_each_with_progress(targets) do |record|
    migrate_record(record)
  end

  log "Migration completed"
end

#migrate_record(record) ⇒ Object

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/dekiru/data_migration/migration.rb', line 38

def migrate_record(record)
  raise NotImplementedError, "#{self.class}#migrate_record must be implemented"
end

#migration_targetsObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/dekiru/data_migration/migration.rb', line 34

def migration_targets
  raise NotImplementedError, "#{self.class}#migration_targets must be implemented"
end

#titleObject



17
18
19
# File 'lib/dekiru/data_migration/migration.rb', line 17

def title
  self.class.name.demodulize.underscore.humanize
end