From 323c5dc26c8061b91b71ba027ee95c6f180061a1 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 1 Feb 2020 20:11:12 -0500 Subject: [PATCH] Adding username and email case insensitivity uniqueness. Fixes #341 --- .../down.sql | 2 ++ .../up.sql | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 server/migrations/2020-02-02-004806_add_case_insensitive_usernames/down.sql create mode 100644 server/migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql diff --git a/server/migrations/2020-02-02-004806_add_case_insensitive_usernames/down.sql b/server/migrations/2020-02-02-004806_add_case_insensitive_usernames/down.sql new file mode 100644 index 000000000..0c6f112f0 --- /dev/null +++ b/server/migrations/2020-02-02-004806_add_case_insensitive_usernames/down.sql @@ -0,0 +1,2 @@ +drop index idx_user_name_lower; +drop index idx_user_email_lower; diff --git a/server/migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql b/server/migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql new file mode 100644 index 000000000..07f854b1c --- /dev/null +++ b/server/migrations/2020-02-02-004806_add_case_insensitive_usernames/up.sql @@ -0,0 +1,29 @@ +-- 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 = ''; +