pact_broker 2.67.0 → 2.68.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 +10 -0
- data/Gemfile +1 -1
- data/db/migrations/20201023_create_verification_number_sequence.rb +20 -0
- data/db/migrations/20201024_create_version_order_sequence.rb +20 -0
- data/lib/db.rb +4 -0
- data/lib/pact_broker/api/resources/label.rb +0 -1
- data/lib/pact_broker/app.rb +2 -2
- data/lib/pact_broker/doc/views/integrations.markdown +5 -1
- data/lib/pact_broker/matrix/deployment_status_summary.rb +1 -1
- data/lib/pact_broker/verifications/repository.rb +16 -9
- data/lib/pact_broker/verifications/sequence.rb +21 -16
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/sequence.rb +21 -17
- data/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb +7 -2
- data/spec/lib/pact_broker/db/delete_overwritten_data_spec.rb +1 -1
- data/spec/lib/pact_broker/matrix/integration_spec.rb +1 -1
- data/spec/lib/pact_broker/verifications/sequence_spec.rb +48 -22
- data/tasks/database.rb +8 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09772ac584dd72c870b97fcaf82485425a5c506f7ab0b8a30bc0ce23eb071484'
|
4
|
+
data.tar.gz: 34ae1ca468c7ebbecfb49570b9374be0db7792da67476ae46d73667c9323615c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d3de22aee4d8d8f106c26fa2eec1148c5f5535d9b2fc34f33c26cb9ef67fa193eddf833865a041479fd4a67bb8be59fb06bb17f79117416575612c37301299
|
7
|
+
data.tar.gz: 73f0a9e7b14e74a9d685ff1039cf1650bf76f9b47ee863acf71a90dd81449684183c35797889c6682e95239c4f9f9bfd57de4050aef60d6a6521fd0a8a274189
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
<a name="v2.68.0"></a>
|
2
|
+
### v2.68.0 (2020-10-23)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* use a sequence for the version order on postgres ([da497a76](/../../commit/da497a76))
|
7
|
+
* only cascade apps for 404s (not 405s) ([4e1b3083](/../../commit/4e1b3083))
|
8
|
+
* use a sequence for the verification number on postgres ([b8f029ee](/../../commit/b8f029ee))
|
9
|
+
* optimise query to find latest verification for pact ([db17ef5a](/../../commit/db17ef5a))
|
10
|
+
|
1
11
|
<a name="v2.67.0"></a>
|
2
12
|
### v2.67.0 (2020-10-16)
|
3
13
|
|
data/Gemfile
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'migration_helper'
|
2
|
+
|
3
|
+
Sequel.migration do
|
4
|
+
up do
|
5
|
+
if PactBroker::MigrationHelper.postgres?
|
6
|
+
row = from(:verification_sequence_number).select(:value).limit(1).first
|
7
|
+
start = row ? row[:value] + 100 : 1
|
8
|
+
run("CREATE SEQUENCE verification_number_sequence START WITH #{start}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
down do
|
13
|
+
if PactBroker::MigrationHelper.postgres?
|
14
|
+
nextval = execute("SELECT nextval('verification_number_sequence') as val") { |v| v.first["val"].to_i }
|
15
|
+
# Add a safety margin!
|
16
|
+
from(:verification_sequence_number).update(value: nextval + 100)
|
17
|
+
run("DROP SEQUENCE verification_number_sequence")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'migration_helper'
|
2
|
+
|
3
|
+
Sequel.migration do
|
4
|
+
up do
|
5
|
+
if PactBroker::MigrationHelper.postgres?
|
6
|
+
row = from(:version_sequence_number).select(:value).limit(1).first
|
7
|
+
start = row ? row[:value] + 100 : 1
|
8
|
+
run("CREATE SEQUENCE version_order_sequence START WITH #{start}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
down do
|
13
|
+
if PactBroker::MigrationHelper.postgres?
|
14
|
+
nextval = execute("SELECT nextval('version_order_sequence') as val") { |v| v.first["val"].to_i }
|
15
|
+
# Add a safety margin!
|
16
|
+
from(:version_sequence_number).update(value: nextval + 100)
|
17
|
+
run("DROP SEQUENCE version_order_sequence")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/db.rb
CHANGED
data/lib/pact_broker/app.rb
CHANGED
@@ -213,7 +213,7 @@ module PactBroker
|
|
213
213
|
builder.use @make_it_later_api_auth
|
214
214
|
builder.use Rack::PactBroker::Convert404ToHal
|
215
215
|
builder.use Rack::PactBroker::DatabaseTransaction, configuration.database_connection
|
216
|
-
builder.run Rack::Cascade.new(api_apps)
|
216
|
+
builder.run Rack::Cascade.new(api_apps, [404])
|
217
217
|
builder
|
218
218
|
end
|
219
219
|
|
@@ -244,7 +244,7 @@ module PactBroker
|
|
244
244
|
prepare_app
|
245
245
|
apps = @cascade_apps
|
246
246
|
@app_builder.map "/" do
|
247
|
-
run Rack::Cascade.new(apps)
|
247
|
+
run Rack::Cascade.new(apps, [404])
|
248
248
|
end
|
249
249
|
@app_builder
|
250
250
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# Integrations
|
2
2
|
|
3
|
-
Allowed methods: `GET`
|
3
|
+
Allowed methods: `GET`, `DELETE`
|
4
|
+
|
5
|
+
Path: `/integrations`
|
4
6
|
|
5
7
|
Content types: `text/vnd.graphviz`, `application/hal+json`
|
6
8
|
|
7
9
|
A list of all the integrations (consumer/provider pairs) stored in the Pact Broker.
|
10
|
+
|
11
|
+
Sending a `DELETE` request to this endpoint will remove all data irretrievably from the Pact Broker.
|
@@ -87,20 +87,27 @@ module PactBroker
|
|
87
87
|
# belonging to the version with the largest consumer_version_order.
|
88
88
|
|
89
89
|
def find_latest_verification_for consumer_name, provider_name, consumer_version_tag = nil
|
90
|
-
|
90
|
+
consumer = pacticipant_repository.find_by_name!(consumer_name)
|
91
|
+
provider = pacticipant_repository.find_by_name!(provider_name)
|
92
|
+
join_cols = {
|
93
|
+
Sequel[:lp][:pact_version_id] => Sequel[:verifications][:pact_version_id],
|
94
|
+
Sequel[:lp][:consumer_id] => consumer.id,
|
95
|
+
Sequel[:lp][:provider_id] => provider.id
|
96
|
+
}
|
97
|
+
query = PactBroker::Domain::Verification
|
91
98
|
.select_all_qualified
|
92
|
-
.join(:
|
93
|
-
.
|
94
|
-
.
|
99
|
+
.join(:latest_verification_ids_for_pact_versions, { Sequel[:verifications][:id] => Sequel[:lv][:latest_verification_id] }, { table_alias: :lv })
|
100
|
+
.join(:latest_pact_publication_ids_for_consumer_versions, join_cols, { table_alias: :lp })
|
101
|
+
.join(:versions, { Sequel[:cv][:id] => Sequel[:lp][:consumer_version_id] }, { table_alias: :cv })
|
95
102
|
if consumer_version_tag == :untagged
|
96
|
-
query = query.
|
103
|
+
query = query.left_outer_join(:tags, { Sequel[:cv][:id] => Sequel[:tags][:version_id] })
|
104
|
+
.where(Sequel[:tags][:name] => nil)
|
97
105
|
elsif consumer_version_tag
|
98
|
-
query = query.
|
106
|
+
query = query.join(:tags, { Sequel[:cv][:id] => Sequel[:tags][:version_id], Sequel[:tags][:name] => consumer_version_tag })
|
99
107
|
end
|
100
108
|
query.reverse_order(
|
101
|
-
Sequel[:
|
102
|
-
Sequel[:
|
103
|
-
Sequel[LatestVerificationForPactVersion.table_name][:number]
|
109
|
+
Sequel[:cv][:order],
|
110
|
+
Sequel[:verifications][:number]
|
104
111
|
).limit(1).single_record
|
105
112
|
end
|
106
113
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sequel'
|
2
|
+
require 'pact_broker/repositories/helpers'
|
2
3
|
|
3
4
|
module PactBroker
|
4
5
|
module Verifications
|
@@ -7,22 +8,26 @@ module PactBroker
|
|
7
8
|
# The easiest way to implement a cross database compatible sequence.
|
8
9
|
# Sad, I know.
|
9
10
|
def next_val
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
if PactBroker::Repositories::Helpers.postgres?
|
12
|
+
db.execute("SELECT nextval('verification_number_sequence') as val") { |v| v.first["val"].to_i }
|
13
|
+
else
|
14
|
+
db.transaction do
|
15
|
+
for_update.first
|
16
|
+
select_all.update(value: Sequel[:value]+1)
|
17
|
+
row = first
|
18
|
+
if row
|
19
|
+
row.value
|
20
|
+
else
|
21
|
+
# The first row should have been created in the migration, so this code
|
22
|
+
# should only ever be executed in a test context.
|
23
|
+
# There would be a risk of a race condition creating two rows if this
|
24
|
+
# code executed in prod, as I don't think you can lock an empty table
|
25
|
+
# to prevent another record being inserted.
|
26
|
+
max_verification_number = PactBroker::Domain::Verification.max(:number)
|
27
|
+
value = max_verification_number ? max_verification_number + 100 : 1
|
28
|
+
insert(value: value)
|
29
|
+
value
|
30
|
+
end
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
data/lib/pact_broker/version.rb
CHANGED
@@ -8,23 +8,27 @@ module PactBroker
|
|
8
8
|
# The easiest way to implement a cross database compatible sequence.
|
9
9
|
# Sad, I know.
|
10
10
|
def next_val
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
11
|
+
if PactBroker::Repositories::Helpers.postgres?
|
12
|
+
db.execute("SELECT nextval('version_order_sequence') as val") { |v| v.first["val"].to_i }
|
13
|
+
else
|
14
|
+
db.transaction do
|
15
|
+
for_update.first
|
16
|
+
select_all.update(value: Sequel[:value]+1)
|
17
|
+
row = first
|
18
|
+
if row
|
19
|
+
row.value
|
20
|
+
else
|
21
|
+
# The first row should have been created in the migration, so this code
|
22
|
+
# should only ever be executed in a test context, after we've truncated all the
|
23
|
+
# tables after a test.
|
24
|
+
# There would be a risk of a race condition creating two rows if this
|
25
|
+
# code executed in prod, as I don't think you can lock an empty table
|
26
|
+
# to prevent another record being inserted.
|
27
|
+
max_version_order = PactBroker::Domain::Version.max(:order)
|
28
|
+
value = max_version_order ? max_version_order + 100 : 1
|
29
|
+
insert(value: value)
|
30
|
+
value
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
@@ -141,8 +141,13 @@ module PactBroker
|
|
141
141
|
|
142
142
|
ALL_RESOURCES.each do | resource_class |
|
143
143
|
describe resource_class do
|
144
|
-
|
145
|
-
|
144
|
+
before do
|
145
|
+
# stub out all path info params for pf
|
146
|
+
allow(path_info).to receive(:[]).and_return('1')
|
147
|
+
end
|
148
|
+
let(:request) { double('request', uri: URI("http://example.org"), path_info: path_info).as_null_object }
|
149
|
+
let(:path_info) { {} }
|
150
|
+
let(:response) { double('response').as_null_object }
|
146
151
|
let(:resource) { resource_class.new(request, response) }
|
147
152
|
|
148
153
|
it "includes OPTIONS in the list of allowed_methods" do
|
@@ -2,7 +2,7 @@ require 'pact_broker/db/delete_overwritten_data'
|
|
2
2
|
|
3
3
|
module PactBroker
|
4
4
|
module DB
|
5
|
-
describe DeleteOverwrittenData, pending:
|
5
|
+
describe DeleteOverwrittenData, pending: !!DB.mysql? do
|
6
6
|
describe ".call" do
|
7
7
|
let(:db) { PactBroker::DB.connection }
|
8
8
|
subject { DeleteOverwrittenData.call(db, before: before_date) }
|
@@ -455,7 +455,7 @@ module PactBroker
|
|
455
455
|
|
456
456
|
let(:options) { { latestby: "cvpv"} }
|
457
457
|
|
458
|
-
|
458
|
+
xit "should include a warning" do
|
459
459
|
expect(subject.deployment_status_summary.reasons.last).to be_a(PactBroker::Matrix::InteractionsMissingVerifications)
|
460
460
|
end
|
461
461
|
end
|
@@ -4,41 +4,67 @@ module PactBroker
|
|
4
4
|
module Verifications
|
5
5
|
describe Sequence do
|
6
6
|
describe "#next_val", migration: true do
|
7
|
+
context "for proper databases with proper sequences", skip: !::DB.postgres? do
|
8
|
+
it "increments the value each time" do
|
9
|
+
PactBroker::Database.migrate
|
10
|
+
expect(Sequence.next_val).to eq 200
|
11
|
+
expect(Sequence.next_val).to eq 201
|
12
|
+
end
|
7
13
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
it "can rollback without duplicating a sequence number" do
|
15
|
+
PactBroker::Database.migrate
|
16
|
+
row = database.from(:verification_sequence_number).select(:value).limit(1).first
|
17
|
+
expect(row[:value]).to eq 100
|
18
|
+
Sequence.next_val
|
19
|
+
PactBroker::Database.migrate(20201006)
|
20
|
+
row = database.from(:verification_sequence_number).select(:value).limit(1).first
|
21
|
+
expect(row[:value]).to eq 301
|
16
22
|
end
|
17
23
|
|
18
|
-
it "
|
19
|
-
|
24
|
+
it "can deal with there not being an existing value in the verification_sequence_number table" do
|
25
|
+
PactBroker::Database.migrate(20201006)
|
26
|
+
database.from(:verification_sequence_number).delete
|
27
|
+
PactBroker::Database.migrate
|
28
|
+
expect(Sequence.next_val).to eq 1
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
23
|
-
context "
|
32
|
+
context "for databases without sequences", skip: ::DB.postgres? do
|
24
33
|
before do
|
25
|
-
|
34
|
+
PactBroker::Database.migrate
|
26
35
|
end
|
27
36
|
|
28
|
-
|
29
|
-
|
37
|
+
context "when there is a row in the verification_sequence_number table" do
|
38
|
+
before do
|
39
|
+
Sequence.select_all.delete
|
40
|
+
Sequence.insert(value: 1)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "increments the value and returns it" do
|
44
|
+
expect(Sequence.next_val).to eq 2
|
45
|
+
end
|
30
46
|
end
|
31
|
-
end
|
32
47
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
48
|
+
context "when there is no row in the verification_sequence_number table and no existing verifications" do
|
49
|
+
before do
|
50
|
+
Sequence.select_all.delete
|
51
|
+
end
|
52
|
+
|
53
|
+
it "inserts and returns the value 1" do
|
54
|
+
expect(Sequence.next_val).to eq 1
|
55
|
+
end
|
38
56
|
end
|
39
57
|
|
40
|
-
|
41
|
-
|
58
|
+
context "when there is no row in the verification_sequence_number table and there are existing verifications" do
|
59
|
+
before do
|
60
|
+
Sequence.select_all.delete
|
61
|
+
TestDataBuilder.new.create_pact_with_hierarchy("A", "1", "B")
|
62
|
+
.create_verification(provider_version: "2")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "inserts a number that is guaranteed to be higher than any of the existing verification numbers from when we tried to do this without a sequence" do
|
66
|
+
expect(Sequence.next_val).to eq 101
|
67
|
+
end
|
42
68
|
end
|
43
69
|
end
|
44
70
|
end
|
data/tasks/database.rb
CHANGED
@@ -35,6 +35,7 @@ module PactBroker
|
|
35
35
|
def drop_objects
|
36
36
|
drop_views
|
37
37
|
drop_tables
|
38
|
+
drop_sequences
|
38
39
|
end
|
39
40
|
|
40
41
|
def drop_tables
|
@@ -56,6 +57,13 @@ module PactBroker
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
def drop_sequences
|
61
|
+
if psql?
|
62
|
+
database.run('DROP SEQUENCE verification_number_sequence')
|
63
|
+
database.run('DROP SEQUENCE version_order_sequence')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
59
67
|
def create
|
60
68
|
if psql?
|
61
69
|
system('psql postgres -c "create database pact_broker"')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.68.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bethany Skurrie
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-10-
|
13
|
+
date: 2020-10-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -521,6 +521,8 @@ files:
|
|
521
521
|
- db/migrations/20200922_add_event_to_triggered_webhook.rb
|
522
522
|
- db/migrations/20200930_update_latest_triggered_webhooks.rb
|
523
523
|
- db/migrations/20201006_add_wip_to_verification.rb
|
524
|
+
- db/migrations/20201023_create_verification_number_sequence.rb
|
525
|
+
- db/migrations/20201024_create_version_order_sequence.rb
|
524
526
|
- db/migrations/migration_helper.rb
|
525
527
|
- db/test/backwards_compatibility/.rspec
|
526
528
|
- db/test/backwards_compatibility/Appraisals
|