diff --git a/db/ddl_statements/latest_verification_ids_for_consumer_and_provider.rb b/db/ddl_statements/latest_verification_ids_for_consumer_and_provider.rb new file mode 100644 index 000000000..bb8a81050 --- /dev/null +++ b/db/ddl_statements/latest_verification_ids_for_consumer_and_provider.rb @@ -0,0 +1,25 @@ +LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V1 = "select + pv.pacticipant_id as provider_id, + lpp.consumer_id, + max(v.id) as latest_verification_id + from verifications v + join latest_pact_publications_by_consumer_versions lpp + on v.pact_version_id = lpp.pact_version_id + join versions pv + on v.provider_version_id = pv.id + group by pv.pacticipant_id, lpp.consumer_id" + +LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V2 = "select + provider_id, + consumer_id, + max(id) as latest_verification_id + from verifications v + group by provider_id, consumer_id" + + +LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V3 = "select + provider_id, + consumer_id, + max(verification_id) as latest_verification_id + from latest_verification_id_for_pact_version_and_provider_version v + group by provider_id, consumer_id" diff --git a/db/migrations/20180524_create_latest_verifications_for_consumer_and_provider.rb b/db/migrations/20180524_create_latest_verifications_for_consumer_and_provider.rb index eb7dbe4a5..67769e5bd 100644 --- a/db/migrations/20180524_create_latest_verifications_for_consumer_and_provider.rb +++ b/db/migrations/20180524_create_latest_verifications_for_consumer_and_provider.rb @@ -1,17 +1,10 @@ +require_relative '../ddl_statements/latest_verification_ids_for_consumer_and_provider' + Sequel.migration do up do - # The latest verification id for each consumer version tag + # The latest verification id for each consumer/provider create_view(:latest_verification_ids_for_consumer_and_provider, - "select - pv.pacticipant_id as provider_id, - lpp.consumer_id, - max(v.id) as latest_verification_id - from verifications v - join latest_pact_publications_by_consumer_versions lpp - on v.pact_version_id = lpp.pact_version_id - join versions pv - on v.provider_version_id = pv.id - group by pv.pacticipant_id, lpp.consumer_id") + LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V1) # The most recent verification for each consumer/consumer version tag/provider latest_verifications = from(:verifications) diff --git a/db/migrations/20180614_update_latest_verification_ids_for_consumer_and_provider.rb b/db/migrations/20180614_update_latest_verification_ids_for_consumer_and_provider.rb index 7f3af2a70..ec7ddcb67 100644 --- a/db/migrations/20180614_update_latest_verification_ids_for_consumer_and_provider.rb +++ b/db/migrations/20180614_update_latest_verification_ids_for_consumer_and_provider.rb @@ -1,27 +1,15 @@ +require_relative '../ddl_statements/latest_verification_ids_for_consumer_and_provider' + Sequel.migration do up do - # The latest verification id for each consumer version tag + # The latest verification id for each consumer/provider create_or_replace_view(:latest_verification_ids_for_consumer_and_provider, - "select - provider_id, - consumer_id, - max(id) as latest_verification_id - from verifications v - group by provider_id, consumer_id") + LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V2) end down do - # The latest verification id for each consumer version tag + # The latest verification id for each consumer/provider create_or_replace_view(:latest_verification_ids_for_consumer_and_provider, - "select - pv.pacticipant_id as provider_id, - lpp.consumer_id, - max(v.id) as latest_verification_id - from verifications v - join latest_pact_publications_by_consumer_versions lpp - on v.pact_version_id = lpp.pact_version_id - join versions pv - on v.provider_version_id = pv.id - group by pv.pacticipant_id, lpp.consumer_id") + LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V1) end end diff --git a/db/migrations/20201026_update_latest_verification_ids_for_consumer_and_provider.rb b/db/migrations/20201026_update_latest_verification_ids_for_consumer_and_provider.rb new file mode 100644 index 000000000..e1ee1499e --- /dev/null +++ b/db/migrations/20201026_update_latest_verification_ids_for_consumer_and_provider.rb @@ -0,0 +1,14 @@ +require_relative 'migration_helper' +require_relative '../ddl_statements/latest_verification_ids_for_consumer_and_provider' + +Sequel.migration do + up do + create_or_replace_view(:latest_verification_ids_for_consumer_and_provider, + LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V3) + end + + down do + create_or_replace_view(:latest_verification_ids_for_consumer_and_provider, + LATEST_VERIFICATION_IDS_FOR_CONSUMER_AND_PROVIDER_V2) + end +end