fix(auth): lowercase existing usernames for pre-3.2 accounts
Co-authored-by: NoiceHax <yashasprakash021@gmail.com>
This commit is contained in:
1 parent
dd6b5ddf3a
commit
d6a3b8c6d3
3 files changed
+86
-4
No files matched your search
@@ -0,0 +1,24 @@
|
||||
-- Rename only soft-deleted rows that block lowercasing a live username.
|
||||
UPDATE "user" AS d
|
||||
SET "username" = CONCAT(LEFT(d."username", 246), '-', SUBSTRING(MD5(d."user_id"::text) FROM 1 FOR 8))
|
||||
WHERE d."deleted_at" IS NOT NULL
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM "user" AS a
|
||||
WHERE a."deleted_at" IS NULL
|
||||
AND a."user_id" <> d."user_id"
|
||||
AND a."username" <> LOWER(a."username")
|
||||
AND LOWER(a."username") = LOWER(d."username")
|
||||
);
|
||||
|
||||
-- Lowercase live usernames unless another live row would still collide.
|
||||
UPDATE "user" AS u
|
||||
SET "username" = LOWER(u."username")
|
||||
WHERE u."deleted_at" IS NULL
|
||||
AND u."username" <> LOWER(u."username")
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM "user" AS c
|
||||
WHERE c."user_id" <> u."user_id"
|
||||
AND LOWER(c."username") = LOWER(u."username")
|
||||
);
|
||||
Reference in new issue
Block a user