Class: BackfillBranchIdsOnSteps

Inherits:
Ductwork::Migration show all
Defined in:
lib/generators/ductwork/update/templates/db/backfill_branch_ids_on_steps.rb

Constant Summary

Constants included from Ductwork::MigrationHelper

Ductwork::MigrationHelper::AVAILABILITY_CLAIM_INDEX_NAME, Ductwork::MigrationHelper::AVAILABILITY_CLAIM_INDEX_NAMES, Ductwork::MigrationHelper::AVAILABILITY_CLAIM_INDEX_NAME_V2

Instance Method Summary collapse

Methods included from Ductwork::MigrationHelper

#add_availability_claim_index, #add_index_online, #belongs_to, #create_ductwork_table, #drop_invalid_index, #ensure_ddl_transaction_disabled!, #mysql?, #postgresql?, #remove_availability_claim_index, #remove_index_online, #swap_availability_claim_index, #uuid_column_type

Instance Method Details

#downObject



18
19
20
# File 'lib/generators/ductwork/update/templates/db/backfill_branch_ids_on_steps.rb', line 18

def down
  Ductwork::Step.update_all(branch_id: nil)
end

#upObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/generators/ductwork/update/templates/db/backfill_branch_ids_on_steps.rb', line 4

def up
  Ductwork::Pipeline.find_each do |pipeline|
    branch = Ductwork::Branch.create!(
      pipeline: pipeline,
      pipeline_klass: pipeline.klass,
      status: pipeline.status,
      started_at: pipeline.started_at,
      last_advanced_at: pipeline.last_advanced_at,
      completed_at: pipeline.completed_at
    )
    pipeline.steps.update_all(branch_id: branch.id)
  end
end