Skip to content

Commit b5ed17d

Browse files
committed
Lookup usernames case insensitively
1 parent e91ff20 commit b5ed17d

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- no-transaction
2+
-- Copyright 2025 New Vector Ltd.
3+
--
4+
-- SPDX-License-Identifier: AGPL-3.0-only
5+
-- Please see LICENSE in the repository root for full details.
6+
7+
-- Create an index on the username column, lower-cased, so that we can lookup
8+
-- usernames in a case-insensitive manner.
9+
CREATE INDEX CONCURRENTLY users_lower_username_idx
10+
ON users (LOWER(username));

crates/storage-pg/src/user/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl UserRepository for PgUserRepository<'_> {
175175
, deactivated_at
176176
, can_request_admin
177177
FROM users
178-
WHERE username = $1
178+
WHERE LOWER(username) = LOWER($1)
179179
"#,
180180
username,
181181
)

crates/storage/src/user/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub trait UserRepository: Send + Sync {
155155
/// Returns [`Self::Error`] if the underlying repository fails
156156
async fn lookup(&mut self, id: Ulid) -> Result<Option<User>, Self::Error>;
157157

158-
/// Find a [`User`] by its username
158+
/// Find a [`User`] by its username, in a case-insensitive manner
159159
///
160160
/// Returns `None` if no [`User`] was found
161161
///

0 commit comments

Comments
 (0)