Skip to content

Commit 0daa445

Browse files
committed
fix: fix error that occurs in some versions of Sqlite when running 20210702_drop_unused_columns_from_deployed_versions.rb
Fixes: #521
1 parent 30d66cf commit 0daa445

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def all_verifications_v2(connection)
2+
# Need to fully qualify build_url because versions now has a build_url too.
3+
# We don't use this view any more but we get an error when modifying other tables and views
4+
# if we don't update this, so it must force some re-calculation to be done.
5+
# See https://github.com/pact-foundation/pact_broker/issues/521
6+
connection
7+
.from(:verifications)
8+
.select(
9+
Sequel[:verifications][:id],
10+
Sequel[:verifications][:number],
11+
:success,
12+
:provider_version_id,
13+
Sequel[:v][:number].as(:provider_version_number),
14+
Sequel[:v][:order].as(:provider_version_order),
15+
Sequel[:verifications][:build_url],
16+
:pact_version_id,
17+
:execution_date,
18+
Sequel[:verifications][:created_at],
19+
:test_results
20+
).join(:versions, { id: :provider_version_id }, { :table_alias => :v })
21+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require_relative "../ddl_statements/all_verifications"
2+
3+
# Naughtily insert this migration file after the creation of 20211104_switch_integrations_and_temp_integrations.rb
4+
# to fix the all_verifications view before
5+
# dropping the columns in 20210702_drop_unused_columns_from_deployed_versions.rb.
6+
# The update to all_verifications was already applied in
7+
# 20211101_recreate_all_verifications.rb, but some versions of SQLite error
8+
# if the view is not updated first, meaning 20210702 was never run.
9+
# It won't matter if this update runs out of order, as long as it's after
10+
# 20210117_add_branch_to_version.rb
11+
Sequel.migration do
12+
up do
13+
create_or_replace_view(:all_verifications, all_verifications_v2(self))
14+
end
15+
16+
down do
17+
end
18+
end

db/migrations/20211101_recreate_all_verifications.rb

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1+
require_relative "../ddl_statements/all_verifications"
2+
13
Sequel.migration do
24
up do
3-
# need to fully qualify build_url because versions now has a build_url too.
4-
# We don't use this view any more but we get an error when dropping the integrations
5-
# view if we don't update this, so it must force some re-calculation to be done.
6-
create_or_replace_view(:all_verifications,
7-
from(:verifications).select(
8-
Sequel[:verifications][:id],
9-
Sequel[:verifications][:number],
10-
:success,
11-
:provider_version_id,
12-
Sequel[:v][:number].as(:provider_version_number),
13-
Sequel[:v][:order].as(:provider_version_order),
14-
Sequel[:verifications][:build_url],
15-
:pact_version_id,
16-
:execution_date,
17-
Sequel[:verifications][:created_at],
18-
:test_results
19-
).join(:versions, {id: :provider_version_id}, {:table_alias => :v})
20-
)
5+
create_or_replace_view(:all_verifications, all_verifications_v2(self))
216
end
227

238
down do

0 commit comments

Comments
 (0)