fix: add database constraint to enforce minimum username length (#19453)

Username length and format, via regex, are already enforced at the
application layer, but we have some code paths with database queries
where we could optimize away many of the DB query calls if we could be
sure at the database level that the username is never an empty string.

For example: https://github.com/coder/coder/pull/19395

---------

Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
Callum Styan
2025-08-21 07:56:41 -07:00
committed by GitHub
parent 72f58c0483
commit bcdade7d8c
5 changed files with 13 additions and 3 deletions
@@ -0,0 +1,2 @@
ALTER TABLE users
DROP CONSTRAINT IF EXISTS users_username_min_length;
@@ -0,0 +1,3 @@
ALTER TABLE users
ADD CONSTRAINT users_username_min_length
CHECK (length(username) >= 1);