-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: load latest verification for consumer/provider via relationship…
… rather than repository
- Loading branch information
Showing
9 changed files
with
111 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
db/migrations/20180524_create_latest_verifications_for_consumer_and_provider.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Sequel.migration do | ||
up do | ||
# The latest verification id for each consumer version tag | ||
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") | ||
|
||
# The most recent verification for each consumer/consumer version tag/provider | ||
latest_verifications = from(:verifications) | ||
.select( | ||
Sequel[:lv][:consumer_id], | ||
Sequel[:lv][:provider_id], | ||
Sequel[:pv][:sha].as(:pact_version_sha), | ||
Sequel[:prv][:number].as(:provider_version_number), | ||
Sequel[:prv][:order].as(:provider_version_order), | ||
) | ||
.select_append{ verifications.* } | ||
.join(:latest_verification_ids_for_consumer_and_provider, | ||
{ | ||
Sequel[:verifications][:id] => Sequel[:lv][:latest_verification_id], | ||
}, { table_alias: :lv }) | ||
.join(:versions, | ||
{ | ||
Sequel[:verifications][:provider_version_id] => Sequel[:prv][:id] | ||
}, { table_alias: :prv }) | ||
.join(:pact_versions, | ||
{ | ||
Sequel[:verifications][:pact_version_id] => Sequel[:pv][:id] | ||
}, { table_alias: :pv }) | ||
|
||
create_or_replace_view(:latest_verifications_for_consumer_and_provider, latest_verifications) | ||
end | ||
|
||
down do | ||
drop_view(:latest_verifications_for_consumer_and_provider) | ||
drop_view(:latest_verification_ids_for_consumer_and_provider) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/pact_broker/verifications/latest_verification_for_consumer_and_provider.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'pact_broker/domain/verification' | ||
|
||
module PactBroker | ||
module Verifications | ||
|
||
include PactBroker::Repositories::Helpers | ||
|
||
class LatestVerificationForConsumerAndProvider < PactBroker::Domain::Verification | ||
set_dataset(:latest_verifications_for_consumer_and_provider) | ||
|
||
# Don't need to load the pact_version as we do in the superclass, | ||
# as pact_version_sha is included in the view for convenience | ||
def pact_version_sha | ||
values[:pact_version_sha] | ||
end | ||
|
||
def provider_version_number | ||
values[:provider_version_number] | ||
end | ||
|
||
def provider_version_order | ||
values[:provider_version_order] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters