From 0daa445947dfca99f56b8a29544cc9cfc6b4fe93 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sat, 6 Nov 2021 14:03:59 +1100 Subject: [PATCH] fix: fix error that occurs in some versions of Sqlite when running 20210702_drop_unused_columns_from_deployed_versions.rb Fixes: https://github.com/pact-foundation/pact_broker/issues/521 --- db/ddl_statements/all_verifications.rb | 21 +++++++++++++++++++ .../20210701_recreate_all_verifications.rb | 18 ++++++++++++++++ .../20211101_recreate_all_verifications.rb | 21 +++---------------- 3 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 db/ddl_statements/all_verifications.rb create mode 100644 db/migrations/20210701_recreate_all_verifications.rb diff --git a/db/ddl_statements/all_verifications.rb b/db/ddl_statements/all_verifications.rb new file mode 100644 index 000000000..01d36e12d --- /dev/null +++ b/db/ddl_statements/all_verifications.rb @@ -0,0 +1,21 @@ +def all_verifications_v2(connection) + # Need to fully qualify build_url because versions now has a build_url too. + # We don't use this view any more but we get an error when modifying other tables and views + # if we don't update this, so it must force some re-calculation to be done. + # See https://github.com/pact-foundation/pact_broker/issues/521 + connection + .from(:verifications) + .select( + Sequel[:verifications][:id], + Sequel[:verifications][:number], + :success, + :provider_version_id, + Sequel[:v][:number].as(:provider_version_number), + Sequel[:v][:order].as(:provider_version_order), + Sequel[:verifications][:build_url], + :pact_version_id, + :execution_date, + Sequel[:verifications][:created_at], + :test_results + ).join(:versions, { id: :provider_version_id }, { :table_alias => :v }) +end diff --git a/db/migrations/20210701_recreate_all_verifications.rb b/db/migrations/20210701_recreate_all_verifications.rb new file mode 100644 index 000000000..1ef14527d --- /dev/null +++ b/db/migrations/20210701_recreate_all_verifications.rb @@ -0,0 +1,18 @@ +require_relative "../ddl_statements/all_verifications" + +# Naughtily insert this migration file after the creation of 20211104_switch_integrations_and_temp_integrations.rb +# to fix the all_verifications view before +# dropping the columns in 20210702_drop_unused_columns_from_deployed_versions.rb. +# The update to all_verifications was already applied in +# 20211101_recreate_all_verifications.rb, but some versions of SQLite error +# if the view is not updated first, meaning 20210702 was never run. +# It won't matter if this update runs out of order, as long as it's after +# 20210117_add_branch_to_version.rb +Sequel.migration do + up do + create_or_replace_view(:all_verifications, all_verifications_v2(self)) + end + + down do + end +end diff --git a/db/migrations/20211101_recreate_all_verifications.rb b/db/migrations/20211101_recreate_all_verifications.rb index eb5b9c94a..81652b206 100644 --- a/db/migrations/20211101_recreate_all_verifications.rb +++ b/db/migrations/20211101_recreate_all_verifications.rb @@ -1,23 +1,8 @@ +require_relative "../ddl_statements/all_verifications" + Sequel.migration do up do - # need to fully qualify build_url because versions now has a build_url too. - # We don't use this view any more but we get an error when dropping the integrations - # view if we don't update this, so it must force some re-calculation to be done. - create_or_replace_view(:all_verifications, - from(:verifications).select( - Sequel[:verifications][:id], - Sequel[:verifications][:number], - :success, - :provider_version_id, - Sequel[:v][:number].as(:provider_version_number), - Sequel[:v][:order].as(:provider_version_order), - Sequel[:verifications][:build_url], - :pact_version_id, - :execution_date, - Sequel[:verifications][:created_at], - :test_results - ).join(:versions, {id: :provider_version_id}, {:table_alias => :v}) - ) + create_or_replace_view(:all_verifications, all_verifications_v2(self)) end down do