diff --git a/db/ddl_statements/latest_pact_publications_by_consumer_versions.rb b/db/ddl_statements/latest_pact_publications_by_consumer_versions.rb new file mode 100644 index 000000000..7fb60aded --- /dev/null +++ b/db/ddl_statements/latest_pact_publications_by_consumer_versions.rb @@ -0,0 +1,16 @@ +def latest_pact_publications_by_consumer_versions_v2(connection = nil) + "select app.* + from latest_pact_publication_ids_for_consumer_versions lpp + inner join all_pact_publications app + on lpp.consumer_version_id = app.consumer_version_id + and lpp.pact_publication_id = app.id + and lpp.provider_id = app.provider_id" +end + +# Don't need all the join keys, just pact_publication_id +def latest_pact_publications_by_consumer_versions_v3(connection) + "select app.* + from latest_pact_publication_ids_for_consumer_versions lpp + inner join all_pact_publications app + on lpp.pact_publication_id = app.id" +end diff --git a/db/migrations/000028_create_all_pact_publications.rb b/db/migrations/000028_create_all_pact_publications.rb index aad274757..57030e3b8 100644 --- a/db/migrations/000028_create_all_pact_publications.rb +++ b/db/migrations/000028_create_all_pact_publications.rb @@ -23,6 +23,7 @@ # Latest pact_publication (revision) for each provider/consumer version # updated in 20180519_recreate_views.rb + # latest_pact_publications_by_consumer_versions_v1 create_view(:latest_pact_publications_by_consumer_versions, "select app.* from all_pact_publications app diff --git a/db/migrations/20180722_recreate_views.rb b/db/migrations/20180722_recreate_views.rb index 900333cd3..220d9ac3d 100644 --- a/db/migrations/20180722_recreate_views.rb +++ b/db/migrations/20180722_recreate_views.rb @@ -1,14 +1,10 @@ +require_relative '../ddl_statements' + Sequel.migration do up do # Latest pact_publication details for each provider/consumer version create_or_replace_view(:latest_pact_publications_by_consumer_versions, - "select app.* - from latest_pact_publication_ids_for_consumer_versions lpp - inner join all_pact_publications app - on lpp.consumer_version_id = app.consumer_version_id - and lpp.pact_publication_id = app.id - and lpp.provider_id = app.provider_id" - ) + latest_pact_publications_by_consumer_versions_v2(self)) # Latest consumer version order for consumer/provider # Recreate latest_pact_publication_ids_for_consumer_versions view @@ -17,6 +13,7 @@ down do # Latest pact_publication details for each provider/consumer version + # latest_pact_publications_by_consumer_versions_v1 create_or_replace_view(:latest_pact_publications_by_consumer_versions, "select app.* from all_pact_publications app diff --git a/db/migrations/20191030_optimise_latest_pact_publications_by_consumer_versions_.rb b/db/migrations/20191030_optimise_latest_pact_publications_by_consumer_versions_.rb new file mode 100644 index 000000000..243038a82 --- /dev/null +++ b/db/migrations/20191030_optimise_latest_pact_publications_by_consumer_versions_.rb @@ -0,0 +1,13 @@ +require_relative '../ddl_statements' + +Sequel.migration do + up do + create_or_replace_view(:latest_pact_publications_by_consumer_versions, + latest_pact_publications_by_consumer_versions_v3(self)) + end + + down do + create_or_replace_view(:latest_pact_publications_by_consumer_versions, + latest_pact_publications_by_consumer_versions_v2(self)) + end +end