From e4b7c46c7ad0d3647bde059dcf8f9245f8f075d7 Mon Sep 17 00:00:00 2001 From: Michael Lynch Date: Fri, 24 Jan 2025 16:08:04 -0500 Subject: [PATCH] Fix foreign key constraint in entries_data --- .../012-fix-entries_data-foreign-key.sql | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 store/sqlite/migrations/012-fix-entries_data-foreign-key.sql diff --git a/store/sqlite/migrations/012-fix-entries_data-foreign-key.sql b/store/sqlite/migrations/012-fix-entries_data-foreign-key.sql new file mode 100644 index 00000000..2bc6cb4d --- /dev/null +++ b/store/sqlite/migrations/012-fix-entries_data-foreign-key.sql @@ -0,0 +1,21 @@ +-- In migration 003, we didn't update entries_data to point to the new entries +-- table, so we have to fix it here. For some reason, the sqlite3 database +-- driver we were using at the time (mattn/go-sqlite3) didn't notice the +-- violation of the FOREIGN KEY constraint. +CREATE TABLE new_entries_data ( + id TEXT, + chunk_index INTEGER, + chunk BLOB, + FOREIGN KEY (id) REFERENCES entries (id) +); + +INSERT INTO new_entries_data +SELECT + id, + chunk_index, + chunk +FROM entries_data; + +DROP TABLE entries_data; + +ALTER TABLE new_entries_data RENAME TO entries_data;