From 408c84efdcc8f768e5cfe3f1c30accbfebe61716 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 2 Dec 2021 12:27:58 +1100 Subject: [PATCH] feat: call the database clean within a transaction --- lib/pact_broker/db/clean_incremental.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/pact_broker/db/clean_incremental.rb b/lib/pact_broker/db/clean_incremental.rb index ead40d106..81dba6e1f 100644 --- a/lib/pact_broker/db/clean_incremental.rb +++ b/lib/pact_broker/db/clean_incremental.rb @@ -66,13 +66,15 @@ def call if dry_run? dry_run_results else - before_counts = current_counts - PactBroker::Domain::Version.where(id: resolve_ids(version_ids_to_delete)).delete - delete_orphan_pact_versions - after_counts = current_counts - - TABLES.each_with_object({}) do | table_name, comparison_counts | - comparison_counts[table_name.to_s] = { "deleted" => before_counts[table_name] - after_counts[table_name], "kept" => after_counts[table_name] } + db.transaction do + before_counts = current_counts + PactBroker::Domain::Version.where(id: resolve_ids(version_ids_to_delete)).delete + delete_orphan_pact_versions + after_counts = current_counts + + TABLES.each_with_object({}) do | table_name, comparison_counts | + comparison_counts[table_name.to_s] = { "deleted" => before_counts[table_name] - after_counts[table_name], "kept" => after_counts[table_name] } + end end end end