Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbcdade7

Browse files
authored
fix: add database constraint to enforce minimum username length (#19453)
Username length and format, via regex, are already enforced at theapplication layer, but we have some code paths with database querieswhere we could optimize away many of the DB query calls if we could besure at the database level that the username is never an empty string.For example:#19395---------Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent72f58c0 commitbcdade7

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

‎coderd/database/check_constraint.go‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dump.sql‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTERTABLE users
2+
DROPCONSTRAINT IF EXISTS users_username_min_length;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTERTABLE users
2+
ADDCONSTRAINT users_username_min_length
3+
CHECK (length(username)>=1);

‎coderd/database/querier_test.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,8 +1552,11 @@ func TestUpdateSystemUser(t *testing.T) {
15521552

15531553
// When: attempting to update a system user's name.
15541554
_,err=db.UpdateUserProfile(ctx, database.UpdateUserProfileParams{
1555-
ID:systemUser.ID,
1556-
Name:"not prebuilds",
1555+
ID:systemUser.ID,
1556+
Email:systemUser.Email,
1557+
Username:systemUser.Username,
1558+
AvatarURL:systemUser.AvatarURL,
1559+
Name:"not prebuilds",
15571560
})
15581561
// Then: the attempt is rejected by a postgres trigger.
15591562
// require.ErrorContains(t, err, "Cannot modify or delete system users")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp