]> Untitled Git - lemmy.git/blob - server/migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql
07f854b1c99fdeab295d6a13c553c88b91ee472a
[lemmy.git] / server / migrations / 2020-02-02-004806_add_case_insensitive_usernames / up.sql
1 -- Add case insensitive username and email uniqueness
2
3 -- An example of showing the dupes:
4 -- select
5 --   max(id) as id,
6 --   lower(name) as lname,
7 --   count(*)
8 -- from user_
9 -- group by lower(name)
10 -- having count(*) > 1;
11
12 -- Delete username dupes, keeping the first one
13 delete
14 from user_
15 where id not in (
16   select min(id)
17   from user_
18   group by lower(name), lower(fedi_name)
19 );
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 user_ set email = null where email = '';
29