Skip to content

Commit

Permalink
feat: update db clean to remove webhooks triggered by verifications
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 21, 2019
1 parent a10b479 commit f38eeae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/pact_broker/db/clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ def initialize database_connection, options = {}
end

def call
db[:verifications].where(id: db[:head_matrix].select(:verification_id)).invert.delete
# TODO head matrix is the head for the consumer tags, not the provider tags.
# Work out how to keep the head verifications for the provider tags.
verification_ids = db[:verifications].where(id: db[:head_matrix].select(:verification_id)).invert.select(:verification_id)

triggered_webhook_ids = db[:triggered_webhooks].where(verification_id: verification_ids).select(:id)
db[:webhook_executions].where(triggered_webhook_id: triggered_webhook_ids).delete
db[:triggered_webhooks].where(id: triggered_webhook_ids).delete

verification_ids.delete

pp_ids = db[:head_matrix].select(:pact_publication_id)

triggered_webhook_ids = db[:triggered_webhooks].where(pact_publication_id: pp_ids).invert.select(:id)
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/pact_broker/db/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module DB
.create_webhook_execution
.create_deprecated_webhook_execution
.create_verification(provider_version: "30")
.create_verification_webhook
.create_triggered_webhook
.create_webhook_execution
.create_consumer_version("3")
.create_pact
.comment("keep")
Expand Down

0 comments on commit f38eeae

Please sign in to comment.