Skip to content

Commit d7e2ef2

Browse files
committed
feat: support DELETE /integrations for deleting all integration related data at once (pacticipants, pacts, verifications and webhooks)
1 parent 1c0530c commit d7e2ef2

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

lib/pact_broker/api/resources/integrations.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def integrations
3030
end
3131

3232
def delete_resource
33-
integration_service.delete(consumer_name, provider_name)
33+
integration_service.delete_all
3434
true
3535
end
3636
end

lib/pact_broker/db/models.rb

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'pact_broker/webhooks/execution'
2+
require 'pact_broker/webhooks/triggered_webhook'
3+
require 'pact_broker/webhooks/webhook'
4+
require 'pact_broker/pacts/latest_pact_publication_id_by_consumer_version'
5+
require 'pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version'
6+
require 'pact_broker/pacts/pact_publication'
7+
require 'pact_broker/pacts/pact_version'
8+
require 'pact_broker/domain/verification'
9+
require 'pact_broker/domain/tag'
10+
require 'pact_broker/domain/version'
11+
require 'pact_broker/domain/label'
12+
require 'pact_broker/domain/pacticipant'
13+
14+
module PactBroker
15+
INTEGRATIONS_TABLES = [
16+
PactBroker::Webhooks::Execution,
17+
PactBroker::Webhooks::TriggeredWebhook,
18+
PactBroker::Webhooks::Webhook,
19+
PactBroker::Pacts::LatestPactPublicationIdForConsumerVersion,
20+
PactBroker::Verifications::LatestVerificationIdForPactVersionAndProviderVersion,
21+
PactBroker::Domain::Verification,
22+
PactBroker::Pacts::PactPublication,
23+
PactBroker::Pacts::PactVersion,
24+
PactBroker::Domain::Tag,
25+
PactBroker::Domain::Version,
26+
PactBroker::Domain::Label,
27+
PactBroker::Domain::Pacticipant
28+
]
29+
30+
module DB
31+
def self.each_integration_model
32+
INTEGRATIONS_TABLES.each do | model |
33+
yield model
34+
end
35+
end
36+
end
37+
end

lib/pact_broker/integrations/service.rb

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'pact_broker/repositories'
33
require 'pact_broker/logging'
44
require 'pact_broker/integrations/integration'
5+
require 'pact_broker/db/models'
56

67
module PactBroker
78
module Integrations
@@ -41,6 +42,14 @@ def self.delete(consumer_name, provider_name)
4142
pacticipant_service.delete_if_orphan(consumer)
4243
pacticipant_service.delete_if_orphan(provider) unless consumer == provider
4344
end
45+
46+
def self.delete_all
47+
# TODO move all these into their own repositories
48+
PactBroker::DB.each_integration_model do | model |
49+
logger.info("Truncating ", model.table_name)
50+
model.truncate
51+
end
52+
end
4453
end
4554
end
4655
end

lib/pact_broker/test/test_data_builder.rb

+10
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,16 @@ def create_certificate options = {path: 'spec/fixtures/single-certificate.pem'}
332332
self
333333
end
334334

335+
def create_everything_for_an_integration
336+
create_pact_with_verification("Foo", "1", "Bar", "2")
337+
.create_label("label")
338+
.create_consumer_version_tag("master")
339+
.create_provider_version_tag("master")
340+
.create_webhook
341+
.create_triggered_webhook
342+
.create_webhook_execution
343+
end
344+
335345
def model_counter
336346
@@model_counter ||= 0
337347
@@model_counter += 1

spec/lib/pact_broker/integrations/service_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ module Integrations
249249
end
250250
end
251251
end
252+
253+
describe "delete_all" do
254+
before do
255+
td.create_everything_for_an_integration
256+
end
257+
258+
it "doesn't blow up" do
259+
Service.delete_all
260+
end
261+
end
252262
end
253263
end
254264
end

0 commit comments

Comments
 (0)