Class: OnlineMigrations::BackgroundSchemaMigrations::MigrationRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/online_migrations/background_schema_migrations/migration_runner.rb

Overview

Runs single background schema migration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(migration) ⇒ MigrationRunner

Returns a new instance of MigrationRunner.



9
10
11
# File 'lib/online_migrations/background_schema_migrations/migration_runner.rb', line 9

def initialize(migration)
  @migration = migration
end

Instance Attribute Details

#migrationObject (readonly)

Returns the value of attribute migration.



7
8
9
# File 'lib/online_migrations/background_schema_migrations/migration_runner.rb', line 7

def migration
  @migration
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/online_migrations/background_schema_migrations/migration_runner.rb', line 13

def run
  return if migration.cancelled? || migration.succeeded?

  mark_as_running if migration.enqueued? || migration.failed?

  if migration.composite?
    migration.children.each do |child_migration|
      runner = self.class.new(child_migration)
      runner.run
    end
  else
    do_run
  end
end