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;