Skip to content

Commit

Permalink
fix: fix error that occurs in some versions of Sqlite when running 20…
Browse files Browse the repository at this point in the history
…210702_drop_unused_columns_from_deployed_versions.rb

Fixes: #521
  • Loading branch information
bethesque committed Nov 6, 2021
1 parent 30d66cf commit 0daa445
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
21 changes: 21 additions & 0 deletions db/ddl_statements/all_verifications.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions db/migrations/20210701_recreate_all_verifications.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 3 additions & 18 deletions db/migrations/20211101_recreate_all_verifications.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0daa445

Please sign in to comment.