]> Untitled Git - lemmy.git/blob - migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql
Revert "Attempt to fix CI building wrong commits (#3830)"
[lemmy.git] / migrations / 2020-02-02-004806_add_case_insensitive_usernames / up.sql
1 -- Add case insensitive username and email uniqueness
2 -- An example of showing the dupes:
3 -- select
4 --   max(id) as id,
5 --   lower(name) as lname,
6 --   count(*)
7 -- from user_
8 -- group by lower(name)
9 -- having count(*) > 1;
10 -- Delete username dupes, keeping the first one
11 DELETE FROM user_
12 WHERE id NOT IN (
13         SELECT
14             min(id)
15         FROM
16             user_
17         GROUP BY
18             lower(name),
19             lower(fedi_name));
20
21 -- The user index
22 CREATE UNIQUE INDEX idx_user_name_lower ON user_ (lower(name));
23
24 -- Email lower
25 CREATE UNIQUE INDEX idx_user_email_lower ON user_ (lower(email));
26
27 -- Set empty emails properly to null
28 UPDATE
29     user_
30 SET
31     email = NULL
32 WHERE
33     email = '';
34