Skip to content

Commit

Permalink
feat: add pact_version_id to latest_pact_publication_ids table
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 4, 2018
1 parent 3180b4e commit 627ce6d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions db/migrations/20180720_create_latest_pact_publication_ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
# for a pact are deleted together when you delete the pact resource for that
# consumer version, and when that happens, this row will cascade delete.
create_table(:latest_pact_publication_ids_by_consumer_versions, charset: 'utf8') do
foreign_key :consumer_id, :pacticipants, nil: false, on_delete: :cascade # redundant, but speeds up queries by removing need for extra join
foreign_key :consumer_version_id, :versions, nil: false, on_delete: :cascade
foreign_key :provider_id, :pacticipants, nil: false, on_delete: :cascade
foreign_key :pact_publication_id, :pact_publications, nil: false, on_delete: :cascade, unique: true
foreign_key :consumer_id, :pacticipants, null: false, on_delete: :cascade # redundant, but speeds up queries by removing need for extra join
foreign_key :consumer_version_id, :versions, null: false, on_delete: :cascade
foreign_key :provider_id, :pacticipants, null: false, on_delete: :cascade
foreign_key :pact_publication_id, :pact_publications, null: false, on_delete: :cascade, unique: true
foreign_key :pact_version_id, :pact_versions, null: false, on_delete: :cascade
index [:provider_id, :consumer_version_id], unique: true, name: "unq_latest_ppid_prov_conver"
index [:provider_id, :consumer_id], name: "lpp_provider_id_consumer_id_index"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Sequel.migration do
up do
# The danger with this migration is that a pact publication created by an old node will be lost
rows = from(:latest_pact_publications_by_consumer_versions).select(:consumer_id, :consumer_version_id, :provider_id, :id)
rows = from(:latest_pact_publications_by_consumer_versions).select(:consumer_id, :consumer_version_id, :provider_id, :id, :pact_version_id)
from(:latest_pact_publication_ids_by_consumer_versions).insert(rows)
end

Expand Down
4 changes: 3 additions & 1 deletion lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def update_latest_pact_publication_ids(pact_publication)
}

other = {
pact_publication_id: pact_publication.id, consumer_id: pact_publication.consumer_id
pact_publication_id: pact_publication.id,
consumer_id: pact_publication.consumer_id,
pact_version_id: pact_publication.pact_version_id
}

row = key.merge(other)
Expand Down

0 comments on commit 627ce6d

Please sign in to comment.