From 852324ae913971948f9b0af57bd857a370327f48 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sat, 4 Nov 2017 16:16:21 +1100 Subject: [PATCH] feat(matrix): add matrix view --- db/migrations/000048_create_matrix.rb | 36 +++++++++++++++++++++++++++ lib/pact_broker/matrix/repository.rb | 12 +++------ lib/pact_broker/matrix/row.rb | 13 ++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 db/migrations/000048_create_matrix.rb create mode 100644 lib/pact_broker/matrix/row.rb diff --git a/db/migrations/000048_create_matrix.rb b/db/migrations/000048_create_matrix.rb new file mode 100644 index 000000000..3126a6052 --- /dev/null +++ b/db/migrations/000048_create_matrix.rb @@ -0,0 +1,36 @@ +Sequel.migration do + up do + p = :latest_pact_publications_by_consumer_versions + create_view(:matrix, + from(p) + .select( + Sequel[p][:consumer_id], + Sequel[p][:consumer_name], + Sequel[p][:consumer_version_id], + Sequel[p][:consumer_version_number], + Sequel[p][:consumer_version_order], + Sequel[p][:id].as(:pact_publication_id), + Sequel[p][:pact_version_id], + Sequel[p][:pact_version_sha], + Sequel[p][:revision_number], + Sequel[p][:created_at].as(:pact_created_at), + Sequel[p][:provider_id], + Sequel[p][:provider_name], + Sequel[:versions][:id].as(:provider_version_id), + Sequel[:versions][:number].as(:provider_version_number), + Sequel[:versions][:order].as(:provider_version_order), + Sequel[:verifications][:success], + Sequel[:verifications][:number], + Sequel[:verifications][:id].as(:verification_id), + Sequel[:verifications][:execution_date].as(:verification_executed_at), + Sequel[:verifications][:build_url].as(:verification_build_url) + ) + .left_outer_join(:verifications, { Sequel[:verifications][:pact_version_id] => Sequel[p][:pact_version_id] }) + .left_outer_join(:versions, {Sequel[:versions][:id] => Sequel[:verifications][:provider_version_id]}) + ) + end + + down do + drop_view(:matrix) + end +end diff --git a/lib/pact_broker/matrix/repository.rb b/lib/pact_broker/matrix/repository.rb index 848aab83f..6174f855a 100644 --- a/lib/pact_broker/matrix/repository.rb +++ b/lib/pact_broker/matrix/repository.rb @@ -1,4 +1,5 @@ require 'pact_broker/repositories/helpers' +require 'pact_broker/matrix/row' module PactBroker module Matrix @@ -67,14 +68,7 @@ def find_compatible_pacticipant_versions selectors # def find_all selectors selectors = look_up_versions_for_tags(selectors) - - query = PactBroker::Pacts::LatestPactPublicationsByConsumerVersion - .select_append(:consumer_version_number, :provider_name, :consumer_name, :provider_version_id, :provider_version_number, :success) - .select_append(Sequel[:latest_pact_publications_by_consumer_versions][:created_at].as(:pact_created_at)) - .select_append(Sequel[:all_verifications][:number]) - .select_append(Sequel[:all_verifications][:id].as(:verification_id)) - .select_append(Sequel[:execution_date].as(:verification_executed_at)) - .left_outer_join(:all_verifications, pact_version_id: :pact_version_id) + query = Row.select_all if selectors.size == 1 query = where_consumer_or_provider_is(selectors.first, query) @@ -82,7 +76,7 @@ def find_all selectors query = where_consumer_and_provider_within(selectors, query) end - query.order(:execution_date, :verification_id) + query.order(:verification_executed_at, :verification_id) .collect(&:values) end diff --git a/lib/pact_broker/matrix/row.rb b/lib/pact_broker/matrix/row.rb new file mode 100644 index 000000000..b1a4a5923 --- /dev/null +++ b/lib/pact_broker/matrix/row.rb @@ -0,0 +1,13 @@ +require 'pact_broker/repositories/helpers' + +module PactBroker + module Matrix + class Row < Sequel::Model + set_dataset(:matrix) + + dataset_module do + include PactBroker::Repositories::Helpers + end + end + end +end