Created
May 25, 2022 13:20
-
-
Save ItsOnlyBinary/c3c8051553f0f2a1ebde6dfcb4e842b0 to your computer and use it in GitHub Desktop.
SQL Queries for purgin old data from kiwibnc messages.db
This file contains hidden or 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
/* Test how many records the UTC date would remove */ | |
SELECT (SELECT COUNT(*) FROM logs WHERE time <= strftime('%s000','2022-05-25 12:50:00')) || '/' || (SELECT COUNT(*) FROM logs) | |
/* Remove records from logs before the set UTC date */ | |
DELETE FROM logs WHERE time <= strftime('%s000','2022-05-25 12:31:00'); | |
/* Clean data of any orphaned records */ | |
DELETE FROM data WHERE id NOT IN ( | |
SELECT msgtagsref AS ids FROM logs | |
UNION | |
SELECT dataref AS ids FROM logs | |
UNION | |
SELECT prefixref AS ids FROM logs | |
UNION | |
SELECT paramsref AS ids FROM logs | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment