Skip to content

Commit 627ce6d

Browse files
committed
feat: add pact_version_id to latest_pact_publication_ids table
1 parent 3180b4e commit 627ce6d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

db/migrations/20180720_create_latest_pact_publication_ids.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
# for a pact are deleted together when you delete the pact resource for that
99
# consumer version, and when that happens, this row will cascade delete.
1010
create_table(:latest_pact_publication_ids_by_consumer_versions, charset: 'utf8') do
11-
foreign_key :consumer_id, :pacticipants, nil: false, on_delete: :cascade # redundant, but speeds up queries by removing need for extra join
12-
foreign_key :consumer_version_id, :versions, nil: false, on_delete: :cascade
13-
foreign_key :provider_id, :pacticipants, nil: false, on_delete: :cascade
14-
foreign_key :pact_publication_id, :pact_publications, nil: false, on_delete: :cascade, unique: true
11+
foreign_key :consumer_id, :pacticipants, null: false, on_delete: :cascade # redundant, but speeds up queries by removing need for extra join
12+
foreign_key :consumer_version_id, :versions, null: false, on_delete: :cascade
13+
foreign_key :provider_id, :pacticipants, null: false, on_delete: :cascade
14+
foreign_key :pact_publication_id, :pact_publications, null: false, on_delete: :cascade, unique: true
15+
foreign_key :pact_version_id, :pact_versions, null: false, on_delete: :cascade
1516
index [:provider_id, :consumer_version_id], unique: true, name: "unq_latest_ppid_prov_conver"
1617
index [:provider_id, :consumer_id], name: "lpp_provider_id_consumer_id_index"
1718
end

db/migrations/20180721_migrate_latest_pact_publication_ids.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Sequel.migration do
22
up do
33
# The danger with this migration is that a pact publication created by an old node will be lost
4-
rows = from(:latest_pact_publications_by_consumer_versions).select(:consumer_id, :consumer_version_id, :provider_id, :id)
4+
rows = from(:latest_pact_publications_by_consumer_versions).select(:consumer_id, :consumer_version_id, :provider_id, :id, :pact_version_id)
55
from(:latest_pact_publication_ids_by_consumer_versions).insert(rows)
66
end
77

lib/pact_broker/pacts/repository.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def update_latest_pact_publication_ids(pact_publication)
5555
}
5656

5757
other = {
58-
pact_publication_id: pact_publication.id, consumer_id: pact_publication.consumer_id
58+
pact_publication_id: pact_publication.id,
59+
consumer_id: pact_publication.consumer_id,
60+
pact_version_id: pact_publication.pact_version_id
5961
}
6062

6163
row = key.merge(other)

0 commit comments

Comments
 (0)