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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2874fe6ca6f552e6cba4d848f56998d0473d860ec4aa47530ccf883d9f189cfe
4
- data.tar.gz: b8e28ffebc86a0f28251489edb9cd92407a4f2758e4fdc519f1d47d7c32cbf2d
3
+ metadata.gz: '09772ac584dd72c870b97fcaf82485425a5c506f7ab0b8a30bc0ce23eb071484'
4
+ data.tar.gz: 34ae1ca468c7ebbecfb49570b9374be0db7792da67476ae46d73667c9323615c
5
5
  SHA512:
6
- metadata.gz: f6bae75159d6ed6b50e0c96f71cd0931d52b94e6fb251d21e31153d67ce892dfaecdf64932f0bca27f06418fb61c67b9348129a5f662590c528d401a2a2df27d
7
- data.tar.gz: 31b4370cd7d1e4c9b4b7825f013a58c327a1b3766f62ce59380bd878160dde2725cee60a2401625772b88378cb258ca8d5ebfa927131cdaf66ac1636352e4cda
6
+ metadata.gz: d9d3de22aee4d8d8f106c26fa2eec1148c5f5535d9b2fc34f33c26cb9ef67fa193eddf833865a041479fd4a67bb8be59fb06bb17f79117416575612c37301299
7
+ data.tar.gz: 73f0a9e7b14e74a9d685ff1039cf1650bf76f9b47ee863acf71a90dd81449684183c35797889c6682e95239c4f9f9bfd57de4050aef60d6a6521fd0a8a274189
@@ -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
@@ -25,7 +25,7 @@ group :test do
25
25
  gem 'timecop', '~> 0.9'
26
26
  gem 'faraday', '~>0.15'
27
27
  gem 'docker-api', '~>1.34'
28
- gem 'approvals', '~>0.0.1', '< 1'
28
+ gem 'approvals', '>=0.0.1', '<1.0.0'
29
29
  end
30
30
 
31
31
  if ENV['INSTALL_MYSQL'] == "true"
@@ -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
@@ -60,6 +60,10 @@ module DB
60
60
  !!(PACT_BROKER_DB.adapter_scheme.to_s =~ /mysql/)
61
61
  end
62
62
 
63
+ def self.postgres?
64
+ !!(PACT_BROKER_DB.adapter_scheme.to_s == "postgres")
65
+ end
66
+
63
67
  PACT_BROKER_DB ||= connection_for_env ENV.fetch('RACK_ENV')
64
68
 
65
69
  def self.health_check
@@ -48,6 +48,5 @@ module PactBroker
48
48
  end
49
49
  end
50
50
  end
51
-
52
51
  end
53
52
  end
@@ -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.
@@ -52,7 +52,7 @@ module PactBroker
52
52
  end
53
53
 
54
54
  def warning_messages
55
- warnings_for_missing_interactions
55
+ []
56
56
  end
57
57
 
58
58
  def specified_selectors_that_do_not_exist
@@ -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
- query = LatestVerificationForPactVersion
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(:all_pact_publications, pact_version_id: :pact_version_id)
93
- .consumer(consumer_name)
94
- .provider(provider_name)
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.untagged
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.tag(consumer_version_tag)
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[:all_pact_publications][:consumer_version_order],
102
- Sequel[:all_pact_publications][:revision_number],
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
- db.transaction do
11
- for_update.first
12
- select_all.update(value: Sequel[:value]+1)
13
- row = first
14
- if row
15
- row.value
16
- else
17
- # The first row should have been created in the migration, so this code
18
- # should only ever be executed in a test context.
19
- # There would be a risk of a race condition creating two rows if this
20
- # code executed in prod, as I don't think you can lock an empty table
21
- # to prevent another record being inserted.
22
- max_verification_number = PactBroker::Domain::Verification.max(:number)
23
- value = max_verification_number ? max_verification_number + 100 : 1
24
- insert(value: value)
25
- value
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
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '2.67.0'
2
+ VERSION = '2.68.0'
3
3
  end
@@ -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
- db.transaction do
12
- for_update.first
13
- select_all.update(value: Sequel[:value]+1)
14
- row = first
15
- if row
16
- row.value
17
- else
18
- # The first row should have been created in the migration, so this code
19
- # should only ever be executed in a test context, after we've truncated all the
20
- # tables after a test.
21
- # There would be a risk of a race condition creating two rows if this
22
- # code executed in prod, as I don't think you can lock an empty table
23
- # to prevent another record being inserted.
24
- max_version_order = PactBroker::Domain::Version.max(:order)
25
- value = max_version_order ? max_version_order + 100 : 1
26
- insert(value: value)
27
- value
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
- let(:request) { double('request', uri: URI("http://example.org")).as_null_object }
145
- let(:response) { double('response') }
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: IS_MYSQL do
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
- it "should include a warning" do
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
- before do
9
- PactBroker::Database.migrate
10
- end
11
-
12
- context "when there is a row in the verification_sequence_number table" do
13
- before do
14
- Sequence.select_all.delete
15
- Sequence.insert(value: 1)
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 "increments the value and returns it" do
19
- expect(Sequence.next_val).to eq 2
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 "when there is no row in the verification_sequence_number table and no existing verifications" do
32
+ context "for databases without sequences", skip: ::DB.postgres? do
24
33
  before do
25
- Sequence.select_all.delete
34
+ PactBroker::Database.migrate
26
35
  end
27
36
 
28
- it "inserts and returns the value 1" do
29
- expect(Sequence.next_val).to eq 1
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
- context "when there is no row in the verification_sequence_number table and there are existing verifications" do
34
- before do
35
- Sequence.select_all.delete
36
- TestDataBuilder.new.create_pact_with_hierarchy("A", "1", "B")
37
- .create_verification(provider_version: "2")
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
- 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
41
- expect(Sequence.next_val).to eq 101
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
@@ -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.67.0
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-15 00:00:00.000000000 Z
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