From 627ce6db108f0d02fceef1c45322339fcdd35231 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sat, 4 Aug 2018 14:18:08 +1000 Subject: [PATCH] feat: add pact_version_id to latest_pact_publication_ids table --- .../20180720_create_latest_pact_publication_ids.rb | 9 +++++---- .../20180721_migrate_latest_pact_publication_ids.rb | 2 +- lib/pact_broker/pacts/repository.rb | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/db/migrations/20180720_create_latest_pact_publication_ids.rb b/db/migrations/20180720_create_latest_pact_publication_ids.rb index 71c02a82d..5a0f16ae8 100644 --- a/db/migrations/20180720_create_latest_pact_publication_ids.rb +++ b/db/migrations/20180720_create_latest_pact_publication_ids.rb @@ -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 diff --git a/db/migrations/20180721_migrate_latest_pact_publication_ids.rb b/db/migrations/20180721_migrate_latest_pact_publication_ids.rb index c56d9f5ff..a12ba9c71 100644 --- a/db/migrations/20180721_migrate_latest_pact_publication_ids.rb +++ b/db/migrations/20180721_migrate_latest_pact_publication_ids.rb @@ -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 diff --git a/lib/pact_broker/pacts/repository.rb b/lib/pact_broker/pacts/repository.rb index 960e0d853..7da326bd7 100644 --- a/lib/pact_broker/pacts/repository.rb +++ b/lib/pact_broker/pacts/repository.rb @@ -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)