legacymigrate: move deleting invalid user_portal rows to correct place

This commit is contained in:
Tulir Asokan 2024-10-16 17:03:00 +03:00
parent 07f721458d
commit 220dc219b8

View file

@ -99,6 +99,9 @@ SELECT
) -- metadata
FROM portal_old;
-- only: sqlite
DELETE FROM user_portal_old WHERE rowid IN (SELECT rowid FROM pragma_foreign_key_check('user_portal_old'));
INSERT INTO user_portal (bridge_id, user_mxid, login_id, portal_id, portal_receiver, in_space, preferred, last_read)
SELECT
'', -- bridge_id
@ -120,10 +123,9 @@ UPDATE message_old SET combined_id = chat_jid || ':' || (
END
) || ':' || jid;
DELETE FROM message_old WHERE timestamp<0;
-- only: sqlite for next 3 lines
-- only: sqlite for next 2 lines
DELETE FROM message_old WHERE rowid IN (SELECT rowid FROM pragma_foreign_key_check('message_old'));
DELETE FROM reaction_old WHERE rowid IN (SELECT rowid FROM pragma_foreign_key_check('reaction_old'));
DELETE FROM user_portal_old WHERE rowid IN (SELECT rowid FROM pragma_foreign_key_check('user_portal_old'));
DELETE FROM message_old WHERE sender NOT LIKE '%@s.whatsapp.net' AND sender<>chat_jid;
DELETE FROM reaction_old WHERE sender NOT LIKE '%@s.whatsapp.net';
DELETE FROM reaction_old WHERE NOT EXISTS(SELECT 1 FROM puppet_old WHERE username=replace(sender, '@s.whatsapp.net', ''));