Skip to content

Commit

Permalink
fix(migration): Migrate reports with appropriate default checker ID
Browse files Browse the repository at this point in the history
The first row in a table with an `AUTOINCREMENT` ID has the value 1, not
0. This was synchronised in the migration script to have
`server_default="1"` such that all default constructed `report` rows
have a **valid** `FOREIGN KEY` to the `checkers` table (the `__FAKE__`
checker). But the hand-written upgrade query filtered for `0` to get
a batch of "unhandled rows", essentially preventing appropriate
migration.
  • Loading branch information
whisperity committed Mar 12, 2024
1 parent fa1d14f commit 47851be
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ def _print_progress(batch: int):
if batch < num_batches else report_count,
float(batch) / num_batches * 100)

fake_chk_id = db.execute(
"SELECT id FROM checkers WHERE "
f"analyzer_name = '{FakeChecker[0]}' AND "
f"checker_name = '{FakeChecker[1]}';").scalar()
for i in range(0, num_batches):
# FIXME: "UPDATE ... SET ... FROM ..." is only supported starting
# with SQLite version 3.33.0 (2020-08-14). Until this version
Expand All @@ -233,7 +237,9 @@ def _print_progress(batch: int):
WHERE reports.id IN (
SELECT reports.id
FROM reports
WHERE reports.checker_id = 0
WHERE reports.checker_id = {fake_chk_id}
AND reports.analyzer_name != '{FakeChecker[0]}'
AND reports.checker_name != '{FakeChecker[1]}'
LIMIT {REPORT_UPDATE_CHUNK_SIZE}
)
;
Expand All @@ -249,7 +255,9 @@ def _print_progress(batch: int):
AND reports.id IN (
SELECT reports.id
FROM reports
WHERE reports.checker_id = 0
WHERE reports.checker_id = {fake_chk_id}
AND reports.analyzer_name != '{FakeChecker[0]}'
AND reports.checker_name != '{FakeChecker[1]}'
LIMIT {REPORT_UPDATE_CHUNK_SIZE}
)
;
Expand Down Expand Up @@ -473,6 +481,10 @@ def _print_progress(batch: int):
if batch < num_batches else report_count,
float(batch) / num_batches * 100)

fake_chk_id = db.execute(
"SELECT id FROM checkers WHERE "
f"analyzer_name = '{FakeChecker[0]}' AND "
f"checker_name = '{FakeChecker[1]}';").scalar()
for i in range(0, num_batches):
# FIXME: "UPDATE ... SET ... FROM ..." is only supported starting
# with SQLite version 3.33.0 (2020-08-14). Until this version
Expand All @@ -484,13 +496,14 @@ def _print_progress(batch: int):
UPDATE reports
SET
(analyzer_name, checker_id, severity, checker_id_lookup) =
(SELECT analyzer_name, checker_name, severity, '0'
(SELECT analyzer_name, checker_name, severity,
'{fake_chk_id}'
FROM checkers
WHERE checkers.id = reports.checker_id_lookup)
WHERE reports.id IN (
SELECT reports.id
FROM reports
WHERE reports.checker_id_lookup != 0
WHERE reports.checker_id_lookup != {fake_chk_id}
LIMIT {REPORT_UPDATE_CHUNK_SIZE}
)
;
Expand All @@ -502,13 +515,13 @@ def _print_progress(batch: int):
analyzer_name = checkers.analyzer_name,
checker_id = checkers.checker_name,
severity = checkers.severity,
checker_id_lookup = 0
checker_id_lookup = {fake_chk_id}
FROM checkers
WHERE checkers.id = reports.checker_id_lookup
AND reports.id IN (
SELECT reports.id
FROM reports
WHERE reports.checker_id_lookup != 0
WHERE reports.checker_id_lookup != {fake_chk_id}
LIMIT {REPORT_UPDATE_CHUNK_SIZE}
)
;
Expand Down

0 comments on commit 47851be

Please sign in to comment.