Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Apply fixes to sql migration
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFerr committed Feb 16, 2024
1 parent 4260bc7 commit d9b139a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion database/upgrades/17-refactor-sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ CREATE TABLE reaction_new (
);


DELETE FROM message
WHERE (sender, timestamp, part_index, signal_receiver)
IN (SELECT DISTINCT sender, timestamp, part_index, signal_receiver FROM message GROUP BY (sender, timestamp, part_index, signal_receiver) HAVING COUNT(*)>1);

INSERT INTO message_new
SELECT sender,
CASE WHEN timestamp > 1500000000000000 THEN timestamp / 1000 ELSE timestamp END,
Expand Down Expand Up @@ -90,7 +94,7 @@ CREATE TABLE lost_portals (
receiver TEXT
);
INSERT INTO lost_portals SELECT mxid, chat_id, receiver FROM portal WHERE mxid<>'';
DELETE FROM portal WHERE receiver<>'' AND receiver NOT IN (SELECT username FROM "user" WHERE uuid<>'');
DELETE FROM portal WHERE receiver<>'' AND receiver NOT IN (SELECT username FROM "user" WHERE username IS NOT NULL AND uuid<>'');
UPDATE portal SET receiver=(SELECT uuid FROM "user" WHERE username=receiver AND uuid<>'' LIMIT 1) WHERE receiver<>'';
UPDATE portal SET receiver='00000000-0000-0000-0000-000000000000' WHERE receiver='';
DELETE FROM portal WHERE chat_id NOT LIKE '________-____-____-____-____________' AND LENGTH(chat_id) <> 44;
Expand Down

0 comments on commit d9b139a

Please sign in to comment.