forked from pact-foundation/pact_broker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path000041_migrate_execution_data.rb
47 lines (42 loc) · 1.43 KB
/
000041_migrate_execution_data.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'securerandom'
Sequel.migration do
up do
from(:webhook_executions).each do | execution |
pact_publication = from(:all_pact_publications).where(
consumer_id: execution[:consumer_id],
provider_id: execution[:provider_id]
).where(
Sequel.lit("created_at <= ?", execution[:created_at])
).reverse_order(:id).limit(1).single_record
if pact_publication && execution[:webhook_id]
webhook = from(:webhooks).where(id: execution[:webhook_id]).single_record
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
from(:webhook_executions)
.where(id: execution[:id])
.update(
webhook_id: nil,
consumer_id: nil,
provider_id: nil,
pact_publication_id: nil)
end
end
down do
from(:triggered_webhooks).delete
end
end