Skip to content

Instantly share code, notes, and snippets.

@ItsOnlyBinary
Created May 25, 2022 13:20
Show Gist options
  • Save ItsOnlyBinary/c3c8051553f0f2a1ebde6dfcb4e842b0 to your computer and use it in GitHub Desktop.
Save ItsOnlyBinary/c3c8051553f0f2a1ebde6dfcb4e842b0 to your computer and use it in GitHub Desktop.
SQL Queries for purgin old data from kiwibnc messages.db
/* 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