Class: ActiveRecordMigrationUi::MigrateMigrationScript

Inherits:
Object
  • Object
show all
Includes:
Interactor
Defined in:
app/interactors/active_record_migration_ui/migrate_migration_script.rb

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/interactors/active_record_migration_ui/migrate_migration_script.rb', line 5

def call
  sanity_checks!

  migration_paths = ActiveRecord::Migrator.migrations_paths
  migration_context = ActiveRecord::MigrationContext.new(migration_paths)

  # Lets the logger broadcasting the logs to the UI
  ActiveRecordMigrationUi.running_migration = true

  # In case something went wrong in the migration script, an exception is
  # thrown
  migration_context.migrate(context.version.to_i)

  # Preents the logger to broadcast the logs to the UI
  ActiveRecordMigrationUi.running_migration = false

  context.final_state = 'up'
rescue StandardError => error
  Rails.logger.warn "Migration of #{context.version} failed: " \
                    "#{error.message}"
  context.final_state = 'failed'
end