Skip to content

Commit

Permalink
Handle duplicate logins (ref #408)
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 2, 2024
1 parent 46bf2fe commit 559da81
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion database/upgrades/16-refactor-postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ALTER TABLE portal ADD CONSTRAINT portal_mxid_unique UNIQUE(mxid);
-- Delete any portals that aren't associated with logged-in users.
DELETE FROM portal WHERE receiver<>'' AND receiver NOT IN (SELECT username FROM "user" WHERE uuid IS NOT NULL);
-- Change receiver to uuid instead of phone number, also add nil uuid for groups.
UPDATE portal SET receiver=(SELECT uuid FROM "user" WHERE username=receiver) WHERE receiver<>'';
UPDATE portal SET receiver=(SELECT uuid FROM "user" WHERE username=receiver LIMIT 1) WHERE receiver<>'';
UPDATE portal SET receiver='00000000-0000-0000-0000-000000000000' WHERE receiver='';
-- Drop the foreign keys again to allow changing types (the ON UPDATE CASCADEs are needed for the above step)
ALTER TABLE message DROP CONSTRAINT message_portal_fkey;
Expand Down
2 changes: 1 addition & 1 deletion database/upgrades/17-refactor-sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ CREATE TABLE lost_portals (
);
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<>'');
UPDATE portal SET receiver=(SELECT uuid FROM "user" WHERE username=receiver) WHERE receiver<>'';
UPDATE portal SET receiver=(SELECT uuid FROM "user" WHERE username=receiver 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;
DELETE FROM lost_portals WHERE mxid IN (SELECT mxid FROM portal WHERE mxid<>'');
Expand Down

0 comments on commit 559da81

Please sign in to comment.