-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use a separate table to track the successful verifications of p…
…act versions for each provider version tag (feature toggled with "new_wip_calculation") This is due to performance issues with calculating it using a live query on the verifications table.
- Loading branch information
Showing
10 changed files
with
241 additions
and
10 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
db/migrations/20211120_create_pact_version_provider_tag_successful_verifications.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,23 @@ | ||
Sequel.migration do | ||
up do | ||
create_table(:pact_version_provider_tag_successful_verifications, charset: "utf8") do | ||
primary_key :id | ||
foreign_key :pact_version_id, :pact_versions, null: false, on_delete: :cascade, foreign_key_constraint_name: "pact_version_provider_tag_successful_verifications_pact_version_id_fk" | ||
String :provider_version_tag_name, null: false | ||
Boolean :wip, null: false | ||
Integer :verification_id | ||
DateTime :execution_date, null: false | ||
index([:pact_version_id, :provider_version_tag_name, :wip], unique: true, name: "pact_version_provider_tag_verifications_pv_pvtn_wip_unique") | ||
# The implication of the on_delete: :set_null for verification_id is | ||
# that even if the verification result is deleted from the broker, | ||
# the wip/pending status stays the same. | ||
# We may or may not want this. Will have to wait and see. | ||
# Have made the foreign key a separate declaration so it can more easily be remade. | ||
foreign_key([:verification_id], :verifications, on_delete: :set_null, name: "pact_version_provider_tag_successful_verifications_verification_id_fk") | ||
end | ||
end | ||
|
||
down do | ||
drop_table(:pact_version_provider_tag_successful_verifications) | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
db/migrations/20211121_migrate_pact_version_provider_tag_successful_verifications_data.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,11 @@ | ||
require "pact_broker/db/data_migrations/migrate_pact_version_provider_tag_successful_verifications" | ||
|
||
Sequel.migration do | ||
up do | ||
PactBroker::DB::DataMigrations::MigratePactVersionProviderTagSuccessfulVerifications.call(self) | ||
end | ||
|
||
down do | ||
|
||
end | ||
end |
38 changes: 38 additions & 0 deletions
38
...t_broker/db/data_migrations/migrate_pact_version_provider_tag_successful_verifications.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,38 @@ | ||
require "pact_broker/db/data_migrations/helpers" | ||
|
||
module PactBroker | ||
module DB | ||
module DataMigrations | ||
class MigratePactVersionProviderTagSuccessfulVerifications | ||
extend Helpers | ||
|
||
def self.call(connection) | ||
successful_verifications_join = { | ||
Sequel[:sv][:pact_version_id] => Sequel[:verifications][:pact_version_id], | ||
Sequel[:sv][:provider_version_tag_name] => Sequel[:tags][:name], | ||
Sequel[:sv][:wip] => Sequel[:verifications][:wip] | ||
} | ||
|
||
missing_verifications = connection | ||
.select( | ||
Sequel[:verifications][:pact_version_id], | ||
Sequel[:tags][:name], | ||
Sequel[:verifications][:wip], | ||
Sequel[:verifications][:id], | ||
Sequel[:verifications][:execution_date] | ||
) | ||
.order(Sequel[:verifications][:execution_date], Sequel[:verifications][:id]) | ||
.from(:verifications) | ||
.join(:tags, { Sequel[:verifications][:provider_version_id] => Sequel[:tags][:version_id] }) | ||
.left_outer_join(:pact_version_provider_tag_successful_verifications, successful_verifications_join, { table_alias: :sv }) | ||
.where(Sequel[:sv][:pact_version_id] => nil) | ||
.where(Sequel[:verifications][:success] => true) | ||
|
||
connection[:pact_version_provider_tag_successful_verifications] | ||
.insert_ignore | ||
.insert([:pact_version_id, :provider_version_tag_name, :wip, :verification_id, :execution_date], missing_verifications) | ||
end | ||
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
11 changes: 11 additions & 0 deletions
11
lib/pact_broker/verifications/pact_version_provider_tag_successful_verification.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,11 @@ | ||
require "pact_broker/domain/verification" | ||
|
||
# Represents a non WIP, successful verification for a provider version with a tag. | ||
|
||
module PactBroker | ||
module Verifications | ||
class PactVersionProviderTagSuccessfulVerification < Sequel::Model | ||
plugin :insert_ignore, identifying_columns: [:pact_version_id, :provider_version_tag_name, :wip] | ||
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
51 changes: 51 additions & 0 deletions
51
...ker/db/data_migrations/migrate_pact_version_provider_tag_successful_verifications_spec.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,51 @@ | ||
require 'pact_broker/db/data_migrations/migrate_pact_version_provider_tag_successful_verifications' | ||
|
||
module PactBroker | ||
module DB | ||
module DataMigrations | ||
describe MigratePactVersionProviderTagSuccessfulVerifications do | ||
describe ".call" do | ||
before do | ||
td.set_now(Date.new(2020, 2, 1)) | ||
.publish_pact(consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "1") | ||
.set_now(Date.new(2021, 2, 1)) | ||
.create_verification(provider_version: "2", tag_names: ["feat/x"], wip: true, success: false) | ||
.publish_pact(consumer_name: "Foo", provider_name: "Bar", consumer_version_number: "2") | ||
.set_now(Date.new(2022, 2, 1)) | ||
.create_verification(provider_version: "3", tag_names: ["feat/x"], wip: true, success: true) | ||
.set_now(Date.new(2023, 2, 1)) | ||
.create_verification(provider_version: "4", tag_names: ["feat/x"], wip: true, success: true, number: 2) | ||
.set_now(Date.new(2024, 2, 1)) | ||
.create_verification(provider_version: "5", tag_names: ["feat/x"], wip: false, success: true, number: 3) | ||
.set_now(Date.new(2025, 2, 1)) | ||
.create_verification(provider_version: "6", tag_names: ["feat/x"], wip: false, success: true, number: 4) | ||
|
||
Sequel::Model.db[:pact_version_provider_tag_successful_verifications].delete | ||
end | ||
|
||
subject do | ||
MigratePactVersionProviderTagSuccessfulVerifications.call(Sequel::Model.db) | ||
MigratePactVersionProviderTagSuccessfulVerifications.call(Sequel::Model.db) | ||
end | ||
|
||
let(:first_verification) { Sequel::Model.db[:verifications].where(provider_version_id: Sequel::Model.db[:versions].select(:id).where(number: "3")).first } | ||
let(:last_verification) { Sequel::Model.db[:verifications].where(provider_version_id: Sequel::Model.db[:versions].select(:id).where(number: "5")).first } | ||
|
||
it "uses the date of the first verification for each wip status (true/false) for the row" do | ||
expect { subject }.to change { Sequel::Model.db[:pact_version_provider_tag_successful_verifications].count }.by(2) | ||
|
||
first_row = Sequel::Model.db[:pact_version_provider_tag_successful_verifications].order(:id).first | ||
|
||
expect(first_row[:execution_date].to_s).to include "2022" | ||
expect(first_row[:verification_id]).to eq first_verification[:id] | ||
|
||
last_row = Sequel::Model.db[:pact_version_provider_tag_successful_verifications].order(:id).last | ||
|
||
expect(last_row[:execution_date].to_s).to include "2024" | ||
expect(last_row[:verification_id]).to eq last_verification[:id] | ||
end | ||
end | ||
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