diff --git a/db/ddl_statements/latest_pact_consumer_version_orders.rb b/db/ddl_statements/latest_pact_consumer_version_orders.rb index c7b77aee1..f3194f31e 100644 --- a/db/ddl_statements/latest_pact_consumer_version_orders.rb +++ b/db/ddl_statements/latest_pact_consumer_version_orders.rb @@ -1,3 +1,6 @@ +# The consumer id, provider id, and consumer version order +# for the latest consumer version that has a pact with that provider. + def latest_pact_consumer_version_orders_v1(connection = nil) "select provider_id, consumer_id, max(consumer_version_order) as latest_consumer_version_order from all_pact_publications diff --git a/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb b/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb index 0abd92e1f..f542eec80 100644 --- a/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb +++ b/db/ddl_statements/latest_verification_ids_for_consumer_version_tags.rb @@ -36,3 +36,18 @@ join versions pv on v.provider_version_id = pv.id group by pv.pacticipant_id, lpp.consumer_id, t.name" + +LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V3 = "select + pv.pacticipant_id as provider_id, + lpp.consumer_id, + t.name as consumer_version_tag_name, + max(v.id) as latest_verification_id + from verifications v + join latest_pact_publication_ids_for_consumer_versions lpp + on v.pact_version_id = lpp.pact_version_id + join tags t + on lpp.consumer_version_id = t.version_id + join versions pv + on v.provider_version_id = pv.id + where v.id in (select latest_verification_id from latest_verification_ids_for_pact_versions) + group by pv.pacticipant_id, lpp.consumer_id, t.name" diff --git a/db/ddl_statements/latest_verification_ids_for_pact_versions_v001.rb b/db/ddl_statements/latest_verification_ids_for_pact_versions.rb similarity index 100% rename from db/ddl_statements/latest_verification_ids_for_pact_versions_v001.rb rename to db/ddl_statements/latest_verification_ids_for_pact_versions.rb diff --git a/db/migrations/20191031_optimise_latest_verification_ids_for_consumer_version_tags.rb b/db/migrations/20191031_optimise_latest_verification_ids_for_consumer_version_tags.rb new file mode 100644 index 000000000..a8e0d7d2e --- /dev/null +++ b/db/migrations/20191031_optimise_latest_verification_ids_for_consumer_version_tags.rb @@ -0,0 +1,13 @@ +require_relative '../ddl_statements' + +Sequel.migration do + up do + create_or_replace_view(:latest_verification_ids_for_consumer_version_tags, + LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V3) + end + + down do + create_or_replace_view(:latest_verification_ids_for_consumer_version_tags, + LATEST_VERIFICATION_IDS_FOR_CONSUMER_VERSION_TAGS_V2) + end +end