Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
e438699c
Commit
e438699c
authored
8 years ago
by
Erik Johnston
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1183 from matrix-org/erikj/fix_email_update
Fix user_threepids schema delta
parents
db0609f1
a9111786
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/schema/delta/37/user_threepids.sql
+30
-1
30 additions, 1 deletion
synapse/storage/schema/delta/37/user_threepids.sql
with
30 additions
and
1 deletion
synapse/storage/schema/delta/37/user_threepids.sql
+
30
−
1
View file @
e438699c
...
...
@@ -17,7 +17,36 @@
* Update any email addresses that were stored with mixed case into all
* lowercase
*/
UPDATE
user_threepids
SET
address
=
LOWER
(
address
)
where
medium
=
'email'
;
-- There may be "duplicate" emails (with different case) already in the table,
-- so we find them and move all but the most recently used account.
UPDATE
user_threepids
SET
medium
=
'email_old'
WHERE
medium
=
'email'
AND
address
IN
(
-- We select all the addresses that are linked to the user_id that is NOT
-- the most recently created.
SELECT
u
.
address
FROM
user_threepids
AS
u
,
-- `duplicate_addresses` is a table of all the email addresses that
-- appear multiple times and when the binding was created
(
SELECT
lower
(
u1
.
address
)
AS
address
,
max
(
u1
.
added_at
)
AS
max_ts
FROM
user_threepids
AS
u1
INNER
JOIN
user_threepids
AS
u2
ON
u1
.
medium
=
u2
.
medium
AND
lower
(
u1
.
address
)
=
lower
(
u2
.
address
)
AND
u1
.
address
!=
u2
.
address
WHERE
u1
.
medium
=
'email'
AND
u2
.
medium
=
'email'
GROUP
BY
lower
(
u1
.
address
)
)
AS
duplicate_addresses
WHERE
lower
(
u
.
address
)
=
duplicate_addresses
.
address
AND
u
.
added_at
!=
max_ts
-- NOT the most recently created
);
-- This update is now safe since we've removed the duplicate addresses.
UPDATE
user_threepids
SET
address
=
LOWER
(
address
)
WHERE
medium
=
'email'
;
/* Add an index for the select we do on passwored reset */
CREATE
INDEX
user_threepids_medium_address
on
user_threepids
(
medium
,
address
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment