Skip to content

Commit 68c8a77

Browse files
authored
Fix foreign key reference in database migrations (#707)
The existing migration failed to account for orphaned rows in the download table and entries_data table that referred to files that had been deleted. This fixes the migration so that we only migrate over rows that are not orphaned. Fixes #705
1 parent 8fd6a43 commit 68c8a77

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

store/sqlite/migrations/011-downloads-id-as-text.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ SELECT
1515
download_timestamp,
1616
client_ip,
1717
user_agent
18-
FROM downloads;
18+
FROM downloads
19+
WHERE entry_id IN (SELECT id FROM entries);
1920

2021
DROP TABLE downloads;
2122

store/sqlite/migrations/012-fix-entries_data-foreign-key.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ SELECT
1414
id,
1515
chunk_index,
1616
chunk
17-
FROM entries_data;
17+
FROM entries_data
18+
WHERE id IN (SELECT id FROM entries);
1819

1920
DROP TABLE entries_data;
2021

0 commit comments

Comments
 (0)