-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 460: Set cascade delete pragma on connect.
- add test to ensure stray book stats are deleted - data cleanup migration (one-time only) - remove LanguageRepo.delete, deletes now cascade correctly
- Loading branch information
Showing
6 changed files
with
40 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
lute/db/schema/migrations/20241221_clean_up_missing_relationships.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- Clean up bad data, where relationships are invalid. | ||
-- | ||
-- Per issue 460, the pragma foreign_keys was not ON, so it's possible | ||
-- (though unlikely) that some data in the db is bad/unreachable. | ||
-- | ||
-- This is being done as a one-time fix, rather than as a repeatable | ||
-- migration, as it would be very annoying if the data model changed | ||
-- and I forgot to update the script!! | ||
|
||
DELETE FROM languagedicts WHERE LdLgID NOT IN (SELECT LgID FROM languages); | ||
DELETE FROM wordsread WHERE WrLgID NOT IN (SELECT LgID FROM languages); | ||
|
||
DELETE FROM books WHERE BkLgID NOT IN (SELECT LgID FROM languages); | ||
DELETE FROM bookstats WHERE BkID NOT IN (SELECT BkID FROM books); | ||
DELETE FROM booktags WHERE BtBkID NOT IN (SELECT BkID FROM books) OR BtT2ID NOT IN (SELECT T2ID FROM tags2); | ||
|
||
DELETE FROM texts WHERE TxBkID NOT IN (SELECT BkID FROM books); | ||
DELETE FROM textbookmarks WHERE TbTxID NOT IN (SELECT TxID FROM texts); | ||
DELETE FROM sentences WHERE SeTxID NOT IN (SELECT TxID FROM texts); | ||
DELETE FROM wordsread WHERE WrTxID IS NOT NULL AND WrTxID NOT IN (SELECT TxID FROM texts); | ||
|
||
DELETE FROM wordtags WHERE WtWoID NOT IN (SELECT WoID FROM words) OR WtTgID NOT IN (SELECT TgID FROM tags); | ||
DELETE FROM wordimages WHERE WiWoID NOT IN (SELECT WoID FROM words); | ||
DELETE FROM wordflashmessages WHERE WfWoID NOT IN (SELECT WoID FROM words); | ||
DELETE FROM wordparents WHERE WpWoID NOT IN (SELECT WoID FROM words) OR WpParentWoID NOT IN (SELECT WoID FROM words); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters