mirror of https://github.com/dexidp/dex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
713 B
22 lines
713 B
-- +migrate Up |
|
|
|
-- This migration is a fix for a bug that allowed duplicate emails if they used different cases (see #338). |
|
-- When migrating, dex will not take the liberty of deleting rows for duplicate cases. Instead it will |
|
-- raise an exception and call for an admin to remove duplicates manually. |
|
|
|
CREATE OR REPLACE FUNCTION raise_exp() RETURNS VOID AS $$ |
|
BEGIN |
|
RAISE EXCEPTION 'Found duplicate emails when using case insensitive comparision, cannot perform migration.'; |
|
END; |
|
$$ LANGUAGE plpgsql; |
|
|
|
SELECT LOWER(email), |
|
COUNT(email), |
|
CASE |
|
WHEN COUNT(email) > 1 THEN raise_exp() |
|
ELSE NULL |
|
END |
|
FROM authd_user |
|
GROUP BY LOWER(email); |
|
|
|
UPDATE authd_user SET email = LOWER(email);
|
|
|