lemmy/migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql
Dessalines be1389420b
Adding SQL format checking via pg_format / pgFormatter (#3740)
* SQL format checking, 1.

* SQL format checking, 2.

* SQL format checking, 3.

* SQL format checking, 4.

* SQL format checking, 5.

* Running pg_format

* Getting rid of comment.

* Upping pg_format version.

* Using git ls-files for sql format check.

* Fixing sql lints.

* Addressing PR comments.
2023-08-02 12:44:51 -04:00

34 lines
710 B
SQL

-- Add case insensitive username and email uniqueness
-- An example of showing the dupes:
-- select
-- max(id) as id,
-- lower(name) as lname,
-- count(*)
-- from user_
-- group by lower(name)
-- having count(*) > 1;
-- Delete username dupes, keeping the first one
DELETE FROM user_
WHERE id NOT IN (
SELECT
min(id)
FROM
user_
GROUP BY
lower(name),
lower(fedi_name));
-- The user index
CREATE UNIQUE INDEX idx_user_name_lower ON user_ (lower(name));
-- Email lower
CREATE UNIQUE INDEX idx_user_email_lower ON user_ (lower(email));
-- Set empty emails properly to null
UPDATE
user_
SET
email = NULL
WHERE
email = '';