Skip to content

Commit

Permalink
fix(webhook status): prevent nil webhook for webhook_execution from c…
Browse files Browse the repository at this point in the history
…ausing error during migration
  • Loading branch information
bethesque committed Sep 17, 2017
1 parent 620922b commit 384cddd
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions db/migrations/41_migrate_execution_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@
Sequel.lit("created_at <= ?", execution[:created_at])
).reverse_order(:id).limit(1).single_record

if pact_publication
webhook_uuid = from(:webhooks).where(id: execution[:webhook_id]).single_record[:uuid]
status = execution[:success] ? 'success' : 'failure'
if pact_publication && execution[:webhook_id]
webhook = from(:webhooks).where(id: execution[:webhook_id]).single_record

from(:triggered_webhooks).insert(
trigger_uuid: SecureRandom.urlsafe_base64,
trigger_type: 'pact_publication',
pact_publication_id: pact_publication[:id],
webhook_id: execution[:webhook_id],
webhook_uuid: webhook_uuid,
consumer_id: execution[:consumer_id],
provider_id: execution[:provider_id],
created_at: execution[:created_at],
updated_at: execution[:created_at],
status: status
)
if webhook
webhook_uuid = webhook[:uuid]
status = execution[:success] ? 'success' : 'failure'

from(:triggered_webhooks).insert(
trigger_uuid: SecureRandom.urlsafe_base64,
trigger_type: 'pact_publication',
pact_publication_id: pact_publication[:id],
webhook_id: execution[:webhook_id],
webhook_uuid: webhook_uuid,
consumer_id: execution[:consumer_id],
provider_id: execution[:provider_id],
created_at: execution[:created_at],
updated_at: execution[:created_at],
status: status
)
end
end
end
end
Expand Down

0 comments on commit 384cddd

Please sign in to comment.