Skip to content

Commit

Permalink
feat(matrix): add matrix view
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 6, 2017
1 parent 45c9a4c commit 852324a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
36 changes: 36 additions & 0 deletions db/migrations/000048_create_matrix.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 3 additions & 9 deletions lib/pact_broker/matrix/repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'pact_broker/repositories/helpers'
require 'pact_broker/matrix/row'

module PactBroker
module Matrix
Expand Down Expand Up @@ -67,22 +68,15 @@ 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)
else
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

Expand Down
13 changes: 13 additions & 0 deletions lib/pact_broker/matrix/row.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 852324a

Please sign in to comment.