Skip to content

Commit

Permalink
chore: remove DeprecatedWebhookExecution
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 26, 2020
1 parent 46a5e03 commit 4e42bfa
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'pact_broker/db/data_migrations/helpers'

module PactBroker
module DB
module DataMigrations
class DeleteDeprecatedWebhookExecutions
extend Helpers

def self.call(connection)
if columns_exist?(connection)
connection[:webhook_executions].where(triggered_webhook_id: nil).delete
end
end

def self.columns_exist?(connection)
column_exists?(connection, :webhook_executions, :triggered_webhook_id)
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/pact_broker/db/migrate_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def self.call database_connection, options = {}
DataMigrations::SetConsumerIdsForPactPublications.call(database_connection)
DataMigrations::SetLatestVersionSequenceValue.call(database_connection)
DataMigrations::SetWebhooksEnabled.call(database_connection)
DataMigrations::DeleteDeprecatedWebhookExecutions.call(database_connection)
end
end
end
Expand Down
13 changes: 0 additions & 13 deletions lib/pact_broker/test/test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,6 @@ def create_webhook_execution params = {}
self
end

def create_deprecated_webhook_execution params = {}
params.delete(:comment)
create_webhook_execution params
Sequel::Model.db[:webhook_executions].where(id: webhook_execution.id).update(
triggered_webhook_id: nil,
consumer_id: consumer.id,
provider_id: provider.id,
webhook_id: PactBroker::Webhooks::Webhook.find(uuid: webhook.uuid).id,
pact_publication_id: pact.id
)
self
end

def create_verification parameters = {}
parameters.delete(:comment)
tag_names = [parameters.delete(:tag_names), parameters.delete(:tag_name)].flatten.compact
Expand Down
12 changes: 2 additions & 10 deletions lib/pact_broker/webhooks/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Execution < Sequel::Model(
Sequel[:webhook_executions][:created_at])
)

plugin :timestamps

dataset_module do
include PactBroker::Repositories::Helpers
end
Expand All @@ -25,16 +27,6 @@ def <=> other
comp
end
end

# For a brief time, the code was released with a direct relationship between
# webhook and execution. Need to make sure any existing data is handled properly.
class DeprecatedExecution < Sequel::Model(:webhook_executions)
associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id)
associate(:many_to_one, :consumer, :class => "PactBroker::Domain::Pacticipant", :key => :consumer_id, :primary_key => :id)
end

Execution.plugin :timestamps

end
end

Expand Down
5 changes: 0 additions & 5 deletions lib/pact_broker/webhooks/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ def delete_triggered_webhooks_by_pacticipant pacticipant
end

def delete_executions_by_pacticipant pacticipants
# TODO this relationship no longer exists, deprecate in next version
DeprecatedExecution.where(consumer: pacticipants).delete
DeprecatedExecution.where(provider: pacticipants).delete
execution_ids = Execution
.join(:triggered_webhooks, {id: :triggered_webhook_id})
.where(Sequel.or(
Expand All @@ -151,7 +148,6 @@ def delete_executions_by_pacticipant pacticipants
def delete_triggered_webhooks_by_webhook_uuid uuid
triggered_webhook_ids = TriggeredWebhook.where(webhook: Webhook.where(uuid: uuid)).select_for_subquery(:id)
delete_triggered_webhooks_and_executions(triggered_webhook_ids)
DeprecatedExecution.where(webhook_id: Webhook.where(uuid: uuid).select_for_subquery(:id)).delete
end

def delete_triggered_webhooks_by_version_id version_id
Expand All @@ -166,7 +162,6 @@ def delete_triggered_webhooks_by_verification_ids verification_ids
def delete_triggered_webhooks_by_pact_publication_ids pact_publication_ids
triggered_webhook_ids = TriggeredWebhook.where(pact_publication_id: pact_publication_ids).select_for_subquery(:id)
delete_triggered_webhooks_and_executions(triggered_webhook_ids)
DeprecatedExecution.where(pact_publication_id: pact_publication_ids).delete
end

def find_latest_triggered_webhooks_for_pact pact
Expand Down
1 change: 0 additions & 1 deletion spec/features/delete_pact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
.create_pact_with_hierarchy("A Consumer", "1.2.3", "A Provider")
.create_webhook
.create_triggered_webhook
.create_deprecated_webhook_execution
end

it "deletes the pact" do
Expand Down
1 change: 0 additions & 1 deletion spec/features/delete_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
.create_pact
.create_webhook
.create_triggered_webhook
.create_deprecated_webhook_execution
.and_return(:webhook)
end

Expand Down
1 change: 0 additions & 1 deletion spec/lib/pact_broker/db/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module DB
.create_webhook
.create_triggered_webhook
.create_webhook_execution
.create_deprecated_webhook_execution
.create_verification(provider_version: "30")
.create_verification_webhook
.create_triggered_webhook
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/pacticipants/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module Pacticipants
.create_pact
.create_webhook
.create_triggered_webhook
.create_deprecated_webhook_execution
.create_webhook_execution
.create_verification
end

Expand Down
1 change: 0 additions & 1 deletion spec/lib/pact_broker/pacts/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ module Pacts
.create_webhook
.create_triggered_webhook
.create_webhook_execution
.create_deprecated_webhook_execution
.revise_pact
end

Expand Down
40 changes: 1 addition & 39 deletions spec/lib/pact_broker/webhooks/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,9 @@ module Webhooks
.create_pact
.create_webhook
.create_triggered_webhook
.create_deprecated_webhook_execution
.create_webhook_execution
.create_webhook
.create_triggered_webhook
.create_deprecated_webhook_execution
.create_webhook_execution
end
let(:webhook_id) { Webhook.find(uuid: td.webhook.uuid).id }
Expand All @@ -492,16 +490,10 @@ module Webhooks
}
end

it "deletes the related deprecated webhook executions" do
expect { subject }.to change {
DeprecatedExecution.count
}.by(-2)
end

it "deletes the related webhook executions" do
expect { subject }.to change {
Execution.count
}.by(-2)
}.by(-1)
end
end

Expand Down Expand Up @@ -534,29 +526,6 @@ module Webhooks
.to change { Execution.count }.by(0)
end
end

context "with deprecated executions (before the triggered webhook table was introduced)" do
before do
Sequel::Model.db[:webhook_executions].update(triggered_webhook_id: nil, consumer_id: td.consumer.id, provider_id: td.provider.id)
TriggeredWebhook.select_all.delete
end

it "deletes the execution by consumer" do
expect { Repository.new.delete_executions_by_pacticipant td.consumer }
.to change { Execution.count }.by(-1)
end

it "deletes the execution by provider" do
expect { Repository.new.delete_executions_by_pacticipant td.provider }
.to change { Execution.count }.by(-1)
end

it "does not delete executions for non related pacticipants" do
another_consumer = td.create_consumer.and_return(:consumer)
expect { Repository.new.delete_executions_by_pacticipant another_consumer }
.to change { Execution.count }.by(0)
end
end
end

describe "find_latest_triggered_webhooks" do
Expand Down Expand Up @@ -707,7 +676,6 @@ module Webhooks
.create_webhook
.create_triggered_webhook
.create_webhook_execution
.create_deprecated_webhook_execution
end

subject { Repository.new.delete_triggered_webhooks_by_pact_publication_ids [td.pact.id] }
Expand All @@ -723,12 +691,6 @@ module Webhooks
Execution.exclude(triggered_webhook_id: nil).count
}.by(-1)
end

it "deletes the deprecated webhook_execution" do
expect { subject }.to change {
Execution.exclude(consumer_id: nil).count
}.by(-1)
end
end

describe "delete_triggered_webhooks_by_version_id" do
Expand Down
1 change: 0 additions & 1 deletion spec/lib/pact_broker/webhooks/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ module Webhooks
td.create_pact_with_hierarchy
.create_webhook
.create_triggered_webhook
.create_deprecated_webhook_execution
end

subject { Service.delete_by_uuid td.webhook.uuid }
Expand Down

0 comments on commit 4e42bfa

Please sign in to comment.