pact_broker 2.65.0 → 2.66.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/db/ddl_statements/latest_triggered_webhooks.rb +66 -0
- data/db/migrations/20180119_update_latest_triggered_webhooks.rb +5 -39
- data/db/migrations/20200930_update_latest_triggered_webhooks.rb +15 -0
- data/db/migrations/migration_helper.rb +10 -2
- data/lib/pact_broker/api/decorators/decorator_context.rb +2 -2
- data/lib/pact_broker/api/decorators/pagination_links.rb +34 -0
- data/lib/pact_broker/api/decorators/versions_decorator.rb +5 -1
- data/lib/pact_broker/api/pact_broker_urls.rb +8 -0
- data/lib/pact_broker/api/resources/index.rb +1 -1
- data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +11 -1
- data/lib/pact_broker/api/resources/versions.rb +12 -1
- data/lib/pact_broker/db/clean.rb +100 -43
- data/lib/pact_broker/doc/views/pacticipant/versions.markdown +9 -0
- data/lib/pact_broker/domain/pacticipant.rb +4 -0
- data/lib/pact_broker/domain/tag.rb +2 -0
- data/lib/pact_broker/domain/version.rb +1 -0
- data/lib/pact_broker/feature_toggle.rb +8 -4
- data/lib/pact_broker/matrix/service.rb +3 -0
- data/lib/pact_broker/pacticipants/repository.rb +6 -5
- data/lib/pact_broker/pacticipants/service.rb +5 -18
- data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +15 -1
- data/lib/pact_broker/tags/repository.rb +2 -5
- data/lib/pact_broker/test/test_data_builder.rb +22 -2
- data/lib/pact_broker/ui/views/matrix/show.haml +8 -0
- data/lib/pact_broker/version.rb +1 -1
- data/spec/features/get_versions_spec.rb +8 -0
- data/spec/lib/pact_broker/api/decorators/versions_decorator_spec.rb +14 -9
- data/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb +10 -4
- data/spec/lib/pact_broker/db/clean_spec.rb +72 -4
- data/spec/lib/pact_broker/feature_toggle_spec.rb +9 -1
- data/spec/lib/pact_broker/pacticipants/repository_spec.rb +8 -1
- data/spec/lib/pact_broker/pacts/latest_tagged_pact_publications_spec.rb +99 -0
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +20 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ded381f9c89732b48d2d27f1f9dc7c26708a54c407c6a777a0f698c221d03b5
|
4
|
+
data.tar.gz: 9ac73a1fde0c35b5cc5870e8006556bcc74a5c3765d86ba373b9a91040657b14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15667e1349e7ff6a2484016659d1eee0a26d95471ea6f0f959135f72b2fcf68714a550421a1ff239efa089514ef0064a07602cd84c22f60fedfc82b30a2337a0
|
7
|
+
data.tar.gz: e1c836e2cc3b82096ee5d03c9fe215e5010a7b0eef2aad43781a8713e5e8f8b987fbc86c19d5b5c95c819831a6d07f953a3b8b552d6104b3daddc5a1e62680d0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
<a name="v2.66.0"></a>
|
2
|
+
### v2.66.0 (2020-10-01)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* paginate pacticipant versions ([f489ba7b](/../../commit/f489ba7b))
|
7
|
+
|
8
|
+
* **webhooks**
|
9
|
+
* add event name to group by clause when selecting latest triggered webhooks ([134f12c8](/../../commit/134f12c8))
|
10
|
+
|
11
|
+
#### Bug Fixes
|
12
|
+
|
13
|
+
* maintain latest and tag params when submitting page after following link from can-i-deploy debug logs ([6e2f1a85](/../../commit/6e2f1a85))
|
14
|
+
|
1
15
|
<a name="v2.65.0"></a>
|
2
16
|
### v2.65.0 (2020-09-25)
|
3
17
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# These views find the latest triggered webhook for each webhook/consumer/provider
|
2
|
+
# by finding the latest execution date for each webhook
|
3
|
+
# then taking the row with the max ID in case there there are two
|
4
|
+
# triggered webhooks for the same UUID and same creation date
|
5
|
+
# Not sure if this is strictly necessary to do the extra step, but better to be
|
6
|
+
# safe than sorry.
|
7
|
+
# I probably could just take the max ID for each webhook/consumer/provider, but
|
8
|
+
# something in my head says that
|
9
|
+
# relying on the primary key for order is not a good idea, even though
|
10
|
+
# according to the SQL it should be fine.
|
11
|
+
def latest_triggered_webhook_creation_dates_v2
|
12
|
+
"select webhook_uuid, consumer_id, provider_id, max(created_at) as latest_triggered_webhook_created_at
|
13
|
+
from triggered_webhooks
|
14
|
+
group by webhook_uuid, consumer_id, provider_id"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Ignore ltwcd.latest_triggered_webhook_created_at, it's there because postgres doesn't allow you to modify
|
18
|
+
# the names and types of columns in a view
|
19
|
+
def latest_triggered_webhook_ids_v2
|
20
|
+
"select tw.webhook_uuid, tw.consumer_id, tw.provider_id, ltwcd.latest_triggered_webhook_created_at, max(tw.id) as latest_triggered_webhook_id
|
21
|
+
from latest_triggered_webhook_creation_dates ltwcd
|
22
|
+
inner join triggered_webhooks tw
|
23
|
+
on tw.consumer_id = ltwcd.consumer_id
|
24
|
+
and tw.provider_id = ltwcd.provider_id
|
25
|
+
and tw.webhook_uuid = ltwcd.webhook_uuid
|
26
|
+
and tw.created_at = ltwcd.latest_triggered_webhook_created_at
|
27
|
+
group by tw.webhook_uuid, tw.consumer_id, tw.provider_id, ltwcd.latest_triggered_webhook_created_at"
|
28
|
+
end
|
29
|
+
|
30
|
+
def latest_triggered_webhooks_v2
|
31
|
+
"select tw.*
|
32
|
+
from triggered_webhooks tw
|
33
|
+
inner join latest_triggered_webhook_ids ltwi
|
34
|
+
on tw.consumer_id = ltwi.consumer_id
|
35
|
+
and tw.provider_id = ltwi.provider_id
|
36
|
+
and tw.webhook_uuid = ltwi.webhook_uuid
|
37
|
+
and tw.id = ltwi.latest_triggered_webhook_id"
|
38
|
+
end
|
39
|
+
|
40
|
+
# use explicit columns - can't drop event_name in 20200922_add_event_to_triggered_webhook.rb
|
41
|
+
# if tw.* is used because you can't remove columns from a view in postgres
|
42
|
+
def latest_triggered_webhooks_v3_rollback(is_postgres)
|
43
|
+
if is_postgres
|
44
|
+
"select tw.id, tw.trigger_uuid, tw.trigger_type, tw.pact_publication_id, tw.webhook_id, tw.webhook_uuid, tw.consumer_id, tw.provider_id, tw.status, tw.created_at, tw.updated_at, tw.verification_id, ''::text as event_name
|
45
|
+
from triggered_webhooks tw
|
46
|
+
inner join latest_triggered_webhook_ids ltwi
|
47
|
+
on tw.consumer_id = ltwi.consumer_id
|
48
|
+
and tw.provider_id = ltwi.provider_id
|
49
|
+
and tw.webhook_uuid = ltwi.webhook_uuid
|
50
|
+
and tw.id = ltwi.latest_triggered_webhook_id"
|
51
|
+
else
|
52
|
+
latest_triggered_webhooks_v2
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
##### v3
|
57
|
+
|
58
|
+
# screw dates, just use IDs.
|
59
|
+
def latest_triggered_webhooks_v3
|
60
|
+
"select tw.id, tw.trigger_uuid, tw.trigger_type, tw.pact_publication_id, tw.webhook_id, tw.webhook_uuid, tw.consumer_id, tw.provider_id, tw.status, tw.created_at, tw.updated_at, tw.verification_id, tw.event_name
|
61
|
+
from triggered_webhooks tw
|
62
|
+
inner join (select max(id) as max_id
|
63
|
+
from triggered_webhooks
|
64
|
+
group by webhook_uuid, consumer_id, provider_id, event_name) latest_ids
|
65
|
+
on latest_ids.max_id = tw.id"
|
66
|
+
end
|
@@ -1,44 +1,10 @@
|
|
1
|
+
require_relative '../ddl_statements/latest_triggered_webhooks'
|
2
|
+
|
1
3
|
Sequel.migration do
|
2
4
|
up do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# triggered webhooks for the same UUID and same creation date
|
7
|
-
# Not sure if this is strictly necessary to do the extra step, but better to be
|
8
|
-
# safe than sorry.
|
9
|
-
# I probably could just take the max ID for each webhook/consumer/provider, but
|
10
|
-
# something in my head says that
|
11
|
-
# relying on the primary key for order is not a good idea, even though
|
12
|
-
# according to the SQL it should be fine.
|
13
|
-
|
14
|
-
create_or_replace_view(:latest_triggered_webhook_creation_dates,
|
15
|
-
"select webhook_uuid, consumer_id, provider_id, max(created_at) as latest_triggered_webhook_created_at
|
16
|
-
from triggered_webhooks
|
17
|
-
group by webhook_uuid, consumer_id, provider_id"
|
18
|
-
)
|
19
|
-
|
20
|
-
# Ignore ltwcd.latest_triggered_webhook_created_at, it's there because postgres doesn't allow you to modify
|
21
|
-
# the names and types of columns in a view
|
22
|
-
create_or_replace_view(:latest_triggered_webhook_ids,
|
23
|
-
"select tw.webhook_uuid, tw.consumer_id, tw.provider_id, ltwcd.latest_triggered_webhook_created_at, max(tw.id) as latest_triggered_webhook_id
|
24
|
-
from latest_triggered_webhook_creation_dates ltwcd
|
25
|
-
inner join triggered_webhooks tw
|
26
|
-
on tw.consumer_id = ltwcd.consumer_id
|
27
|
-
and tw.provider_id = ltwcd.provider_id
|
28
|
-
and tw.webhook_uuid = ltwcd.webhook_uuid
|
29
|
-
and tw.created_at = ltwcd.latest_triggered_webhook_created_at
|
30
|
-
group by tw.webhook_uuid, tw.consumer_id, tw.provider_id, ltwcd.latest_triggered_webhook_created_at"
|
31
|
-
)
|
32
|
-
|
33
|
-
create_or_replace_view(:latest_triggered_webhooks,
|
34
|
-
"select tw.*
|
35
|
-
from triggered_webhooks tw
|
36
|
-
inner join latest_triggered_webhook_ids ltwi
|
37
|
-
on tw.consumer_id = ltwi.consumer_id
|
38
|
-
and tw.provider_id = ltwi.provider_id
|
39
|
-
and tw.webhook_uuid = ltwi.webhook_uuid
|
40
|
-
and tw.id = ltwi.latest_triggered_webhook_id"
|
41
|
-
)
|
5
|
+
create_or_replace_view(:latest_triggered_webhook_creation_dates, latest_triggered_webhook_creation_dates_v2)
|
6
|
+
create_or_replace_view(:latest_triggered_webhook_ids, latest_triggered_webhook_ids_v2)
|
7
|
+
create_or_replace_view(:latest_triggered_webhooks, latest_triggered_webhooks_v2)
|
42
8
|
end
|
43
9
|
|
44
10
|
down do
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../ddl_statements/latest_triggered_webhooks'
|
2
|
+
require_relative 'migration_helper'
|
3
|
+
|
4
|
+
Sequel.migration do
|
5
|
+
up do
|
6
|
+
# TODO
|
7
|
+
# drop_view(:latest_triggered_webhook_ids)
|
8
|
+
# drop_view(:latest_triggered_webhook_creation_dates)
|
9
|
+
create_or_replace_view(:latest_triggered_webhooks, latest_triggered_webhooks_v3)
|
10
|
+
end
|
11
|
+
|
12
|
+
down do
|
13
|
+
create_or_replace_view(:latest_triggered_webhooks, latest_triggered_webhooks_v3_rollback(PactBroker::MigrationHelper.postgres?))
|
14
|
+
end
|
15
|
+
end
|
@@ -4,7 +4,7 @@ module PactBroker
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def large_text_type
|
7
|
-
if
|
7
|
+
if postgres?
|
8
8
|
:text
|
9
9
|
else
|
10
10
|
# Assume mysql
|
@@ -13,11 +13,19 @@ module PactBroker
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def with_mysql
|
16
|
-
if
|
16
|
+
if mysql?
|
17
17
|
yield
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def mysql?
|
22
|
+
adapter =~ /mysql/
|
23
|
+
end
|
24
|
+
|
25
|
+
def postgres?
|
26
|
+
adapter == 'postgres'
|
27
|
+
end
|
28
|
+
|
21
29
|
def adapter
|
22
30
|
Sequel::Model.db.adapter_scheme.to_s
|
23
31
|
end
|
@@ -2,14 +2,14 @@ module PactBroker
|
|
2
2
|
module Api
|
3
3
|
module Decorators
|
4
4
|
class DecoratorContext < Hash
|
5
|
-
|
6
|
-
attr_reader :base_url, :resource_url, :resource_title, :env
|
5
|
+
attr_reader :base_url, :resource_url, :resource_title, :env, :query_string
|
7
6
|
|
8
7
|
def initialize base_url, resource_url, env, options = {}
|
9
8
|
@base_url = self[:base_url] = base_url
|
10
9
|
@resource_url = self[:resource_url] = resource_url
|
11
10
|
@resource_title = self[:resource_title] = options[:resource_title]
|
12
11
|
@env = self[:env] = env
|
12
|
+
@query_string = self[:query_string] = (env['QUERY_STRING'] && !env['QUERY_STRING'].empty? ? env['QUERY_STRING'] : nil)
|
13
13
|
merge!(options)
|
14
14
|
end
|
15
15
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'roar/decorator'
|
2
|
+
require 'roar/json/hal'
|
3
|
+
|
4
|
+
module PactBroker
|
5
|
+
module Api
|
6
|
+
module Decorators
|
7
|
+
module PaginationLinks
|
8
|
+
include Roar::JSON::HAL
|
9
|
+
include Roar::JSON::HAL::Links
|
10
|
+
|
11
|
+
link :next do | context |
|
12
|
+
if represented.respond_to?(:current_page) &&
|
13
|
+
represented.respond_to?(:page_count) &&
|
14
|
+
represented.current_page < represented.page_count
|
15
|
+
{
|
16
|
+
href: context[:resource_url] + "?pageSize=#{represented.page_size}&pageNumber=#{represented.current_page + 1}",
|
17
|
+
title: "Next page"
|
18
|
+
}
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
link :previous do | context |
|
24
|
+
if represented.respond_to?(:first_page?) && !represented.first_page?
|
25
|
+
{
|
26
|
+
href: context[:resource_url] + "?pageSize=#{represented.page_size}&pageNumber=#{represented.current_page - 1}",
|
27
|
+
title: "Previous page"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'base_decorator'
|
2
2
|
require_relative 'version_decorator'
|
3
|
+
require_relative 'pagination_links'
|
3
4
|
|
4
5
|
module PactBroker
|
5
6
|
module Api
|
@@ -9,12 +10,15 @@ module PactBroker
|
|
9
10
|
collection :entries, as: :versions, embedded: true, :extend => PactBroker::Api::Decorators::VersionDecorator
|
10
11
|
|
11
12
|
link :self do | context |
|
13
|
+
href = append_query_if_present(context[:resource_url], context[:query_string])
|
12
14
|
{
|
13
|
-
href:
|
15
|
+
href: href,
|
14
16
|
title: "All application versions of #{context[:pacticipant_name]}"
|
15
17
|
}
|
16
18
|
end
|
17
19
|
|
20
|
+
include PaginationLinks
|
21
|
+
|
18
22
|
link :'pb:pacticipant' do | context |
|
19
23
|
{
|
20
24
|
href: pacticipant_url(context[:base_url], OpenStruct.new(name: context[:pacticipant_name])),
|
@@ -307,6 +307,14 @@ module PactBroker
|
|
307
307
|
ERB::Util.url_encode param
|
308
308
|
end
|
309
309
|
|
310
|
+
def append_query_if_present(url, query)
|
311
|
+
if query && query.size > 0
|
312
|
+
url + "?#{query}"
|
313
|
+
else
|
314
|
+
url
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
310
318
|
private
|
311
319
|
|
312
320
|
def representable_pact pact
|
@@ -144,7 +144,7 @@ module PactBroker
|
|
144
144
|
}]
|
145
145
|
}
|
146
146
|
|
147
|
-
if PactBroker.feature_enabled?(
|
147
|
+
if PactBroker.feature_enabled?('disable_pacts_for_verification', true)
|
148
148
|
links_hash.delete('pb:provider-pacts-for-verification')
|
149
149
|
links_hash.delete('beta:provider-pacts-for-verification')
|
150
150
|
end
|
@@ -52,6 +52,7 @@ module PactBroker
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def to_json
|
55
|
+
log_request
|
55
56
|
PactBroker::Api::Decorators::VerifiablePactsDecorator.new(pacts).to_json(
|
56
57
|
decorator_options(
|
57
58
|
include_pending_status: parsed_query_params.include_pending_status,
|
@@ -76,12 +77,21 @@ module PactBroker
|
|
76
77
|
def query
|
77
78
|
@query ||= begin
|
78
79
|
if request.get?
|
79
|
-
|
80
|
+
nested_query
|
80
81
|
elsif request.post?
|
81
82
|
params(symbolize_names: false, default: {})
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
86
|
+
|
87
|
+
def log_request
|
88
|
+
parameters = request.get? ? nested_query : params
|
89
|
+
logger.info "Fetching pacts for verification by #{provider_name}", provider_name: provider_name, params: parameters
|
90
|
+
end
|
91
|
+
|
92
|
+
def nested_query
|
93
|
+
@nested_query ||= Rack::Utils.parse_nested_query(request.uri.query)
|
94
|
+
end
|
85
95
|
end
|
86
96
|
end
|
87
97
|
end
|
@@ -23,12 +23,23 @@ module PactBroker
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def versions
|
26
|
-
@versions ||= pacticipant_service.find_all_pacticipant_versions_in_reverse_order
|
26
|
+
@versions ||= pacticipant_service.find_all_pacticipant_versions_in_reverse_order(pacticipant_name, pagination_options)
|
27
27
|
end
|
28
28
|
|
29
29
|
def policy_name
|
30
30
|
:'versions::versions'
|
31
31
|
end
|
32
|
+
|
33
|
+
def pagination_options
|
34
|
+
if request.query['pageNumber'] || request.query['pageSize']
|
35
|
+
{
|
36
|
+
page_number: request.query['pageNumber']&.to_i || 1,
|
37
|
+
page_size: request.query['pageSize']&.to_i || 100
|
38
|
+
}
|
39
|
+
else
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
end
|
32
43
|
end
|
33
44
|
end
|
34
45
|
end
|
data/lib/pact_broker/db/clean.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
require 'sequel'
|
2
2
|
require 'pact_broker/project_root'
|
3
|
+
require 'pact_broker/pacts/latest_tagged_pact_publications'
|
3
4
|
|
4
5
|
module PactBroker
|
5
6
|
module DB
|
6
7
|
class Clean
|
8
|
+
|
9
|
+
class Unionable < Array
|
10
|
+
alias_method :union, :+
|
11
|
+
|
12
|
+
def union(other)
|
13
|
+
Unionable.new(self + other)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
7
18
|
def self.call database_connection, options = {}
|
8
19
|
new(database_connection, options).call
|
9
20
|
end
|
@@ -13,55 +24,87 @@ module PactBroker
|
|
13
24
|
@options = options
|
14
25
|
end
|
15
26
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
date = options[:date]
|
27
|
+
def keep
|
28
|
+
options[:keep] || [PactBroker::Matrix::UnresolvedSelector.new(tag: true, latest: true)]
|
29
|
+
end
|
20
30
|
|
21
|
-
|
31
|
+
def resolve_ids(query)
|
32
|
+
# query
|
33
|
+
Unionable.new(query.collect { |h| h[:id] })
|
34
|
+
end
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
36
|
+
def pact_publication_ids_to_keep
|
37
|
+
@pact_publication_ids_to_keep ||= pact_publication_ids_to_keep_for_version_ids_to_keep
|
38
|
+
.union(pact_publications_to_keep_for_verification_ids_to_keep)
|
39
|
+
.union(latest_tagged_pact_publications_ids_to_keep)
|
40
|
+
end
|
28
41
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
42
|
+
def pact_publication_ids_to_keep_for_version_ids_to_keep
|
43
|
+
@pact_publication_ids_to_keep_for_version_ids_to_keep ||= resolve_ids(db[:pact_publications].select(:id).where(consumer_version_id: version_ids_to_keep))
|
44
|
+
end
|
45
|
+
|
46
|
+
def pact_publications_to_keep_for_verification_ids_to_keep
|
47
|
+
@pact_publications_to_keep_for_verification_ids_to_keep ||= resolve_ids(db[:pact_publications].select(:id).where(pact_version_id: db[:verifications].select(:pact_version_id).where(id: verification_ids_to_keep_for_version_ids_to_keep)))
|
48
|
+
end
|
49
|
+
|
50
|
+
def latest_tagged_pact_publications_ids_to_keep
|
51
|
+
@latest_tagged_pact_publications_ids_to_keep ||= resolve_ids(keep.select(&:tag).select(&:latest).collect do | selector |
|
52
|
+
PactBroker::Pacts::LatestTaggedPactPublications.select(:id).for_selector(selector)
|
53
|
+
end.reduce(&:union))
|
54
|
+
end
|
55
|
+
|
56
|
+
def pact_publication_ids_to_delete
|
57
|
+
@pact_publication_ids_to_delete ||= resolve_ids(db[:pact_publications].select(:id).where(id: pact_publication_ids_to_keep).invert)
|
58
|
+
end
|
37
59
|
|
60
|
+
# because they belong to the versions to keep
|
61
|
+
def verification_ids_to_keep_for_version_ids_to_keep
|
62
|
+
@verification_ids_to_keep_for_version_ids_to_keep ||= resolve_ids(db[:verifications].select(:id).where(provider_version_id: version_ids_to_keep))
|
63
|
+
end
|
64
|
+
|
65
|
+
def verification_ids_to_keep_for_pact_publication_ids_to_keep
|
66
|
+
@verification_ids_to_keep_for_pact_publication_ids_to_keep ||= resolve_ids(db[:verifications].select(:id).where(pact_version_id: db[:pact_publications].select(:pact_version_id).where(id: pact_publication_ids_to_keep_for_version_ids_to_keep)))
|
67
|
+
end
|
68
|
+
|
69
|
+
def verification_ids_to_keep
|
70
|
+
@verification_ids_to_keep ||= verification_ids_to_keep_for_version_ids_to_keep.union(verification_ids_to_keep_for_pact_publication_ids_to_keep)
|
71
|
+
end
|
72
|
+
|
73
|
+
def verification_ids_to_delete
|
74
|
+
@verification_ids_to_delete ||= db[:verifications].select(:id).where(id: verification_ids_to_keep).invert
|
75
|
+
end
|
76
|
+
|
77
|
+
def version_ids_to_keep
|
78
|
+
@version_ids_to_keep ||= keep.collect do | selector |
|
79
|
+
PactBroker::Domain::Version.select(:id).for_selector(selector)
|
80
|
+
end.reduce(&:union)
|
81
|
+
end
|
82
|
+
|
83
|
+
def call
|
84
|
+
deleted_counts = {}
|
85
|
+
kept_counts = {}
|
38
86
|
|
39
87
|
deleted_counts[:pact_publications] = pact_publication_ids_to_delete.count
|
40
|
-
kept_counts[:pact_publications] =
|
88
|
+
kept_counts[:pact_publications] = pact_publication_ids_to_keep.count
|
41
89
|
|
42
|
-
# TODO head matrix is the head for the consumer tags, not the provider tags.
|
43
90
|
# Work out how to keep the head verifications for the provider tags.
|
44
|
-
verification_ids = get_verification_ids(pact_publication_ids_to_delete)
|
45
|
-
deleted_counts[:verification_results] = verification_ids.count
|
46
|
-
kept_counts[:verification_results] = db[:verifications].where(id:verification_ids ).invert.count
|
47
91
|
|
48
|
-
|
49
|
-
|
92
|
+
deleted_counts[:verification_results] = verification_ids_to_delete.count
|
93
|
+
kept_counts[:verification_results] = verification_ids_to_keep.count
|
50
94
|
|
51
|
-
delete_webhook_data(
|
52
|
-
|
95
|
+
delete_webhook_data(verification_triggered_webhook_ids_to_delete)
|
96
|
+
delete_verifications
|
97
|
+
|
98
|
+
delete_webhook_data(pact_publication_triggered_webhook_ids_to_delete)
|
99
|
+
delete_pact_publications
|
53
100
|
|
54
101
|
delete_orphan_pact_versions
|
55
102
|
overwritten_delete_counts = delete_overwritten_verifications
|
56
103
|
deleted_counts[:verification_results] = deleted_counts[:verification_results] + overwritten_delete_counts[:verification_results]
|
57
104
|
kept_counts[:verification_results] = kept_counts[:verification_results] - overwritten_delete_counts[:verification_results]
|
58
105
|
|
59
|
-
|
60
|
-
|
61
|
-
db[:verifications].select(:provider_version_id).collect{ | h| h[:provider_version_id] }
|
62
|
-
|
63
|
-
delete_orphan_tags(referenced_version_ids)
|
64
|
-
delete_orphan_versions(referenced_version_ids)
|
106
|
+
delete_orphan_tags
|
107
|
+
delete_orphan_versions
|
65
108
|
|
66
109
|
{ kept: kept_counts, deleted: deleted_counts }
|
67
110
|
end
|
@@ -70,8 +113,21 @@ module PactBroker
|
|
70
113
|
|
71
114
|
attr_reader :db, :options
|
72
115
|
|
73
|
-
def
|
74
|
-
db[:
|
116
|
+
def verification_triggered_webhook_ids_to_delete
|
117
|
+
db[:triggered_webhooks].select(:id).where(verification_id: verification_ids_to_delete)
|
118
|
+
end
|
119
|
+
|
120
|
+
def pact_publication_triggered_webhook_ids_to_delete
|
121
|
+
db[:triggered_webhooks].select(:id).where(pact_publication_id: pact_publication_ids_to_delete)
|
122
|
+
end
|
123
|
+
|
124
|
+
def referenced_version_ids
|
125
|
+
db[:pact_publications].select(:consumer_version_id).union(db[:verifications].select(:provider_version_id))
|
126
|
+
end
|
127
|
+
|
128
|
+
def verification_ids_for_pact_publication_ids_to_delete
|
129
|
+
@verification_ids_for_pact_publication_ids_to_delete ||=
|
130
|
+
db[:verifications].select(:id).where(pact_version_id: db[:pact_publications].select(:pact_version_id).where(id: pact_publication_ids_to_delete))
|
75
131
|
end
|
76
132
|
|
77
133
|
def delete_webhook_data(triggered_webhook_ids)
|
@@ -79,23 +135,24 @@ module PactBroker
|
|
79
135
|
db[:triggered_webhooks].where(id: triggered_webhook_ids).delete
|
80
136
|
end
|
81
137
|
|
82
|
-
def delete_pact_publications
|
83
|
-
db[:pact_publications].where(id:
|
84
|
-
|
138
|
+
def delete_pact_publications
|
139
|
+
db[:pact_publications].where(id: pact_publication_ids_to_delete).delete
|
140
|
+
end
|
141
|
+
|
142
|
+
def delete_verifications
|
143
|
+
db[:verifications].where(id: verification_ids_to_delete).delete
|
85
144
|
end
|
86
145
|
|
87
146
|
def delete_orphan_pact_versions
|
88
|
-
|
89
|
-
referenced_pact_version_ids = db[:pact_publications].select(:pact_version_id).collect{ | h| h[:pact_version_id] } +
|
90
|
-
db[:verifications].select(:pact_version_id).collect{ | h| h[:pact_version_id] }
|
147
|
+
referenced_pact_version_ids = db[:pact_publications].select(:pact_version_id).union(db[:verifications].select(:pact_version_id))
|
91
148
|
db[:pact_versions].where(id: referenced_pact_version_ids).invert.delete
|
92
149
|
end
|
93
150
|
|
94
|
-
def delete_orphan_tags
|
151
|
+
def delete_orphan_tags
|
95
152
|
db[:tags].where(version_id: referenced_version_ids).invert.delete
|
96
153
|
end
|
97
154
|
|
98
|
-
def delete_orphan_versions
|
155
|
+
def delete_orphan_versions
|
99
156
|
db[:versions].where(id: referenced_version_ids).invert.delete
|
100
157
|
end
|
101
158
|
|