From 765c638a150046fd317ee46708b566967b5b2a88 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Wed, 6 Dec 2023 18:18:25 +0000 Subject: [PATCH 1/7] db: add theme_preference column to users table --- .../migrations/000174_add_user_theme_preference.down.sql | 0 .../migrations/000174_add_user_theme_preference.up.sql | 3 +++ coderd/database/migrations/create_migration.sh | 8 ++++---- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 coderd/database/migrations/000174_add_user_theme_preference.down.sql create mode 100644 coderd/database/migrations/000174_add_user_theme_preference.up.sql diff --git a/coderd/database/migrations/000174_add_user_theme_preference.down.sql b/coderd/database/migrations/000174_add_user_theme_preference.down.sql new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/coderd/database/migrations/000174_add_user_theme_preference.up.sql b/coderd/database/migrations/000174_add_user_theme_preference.up.sql new file mode 100644 index 0000000000000..fd651157c7668 --- /dev/null +++ b/coderd/database/migrations/000174_add_user_theme_preference.up.sql @@ -0,0 +1,3 @@ +ALTER TABLE users ADD COLUMN "theme_preference" text; + +COMMENT ON COLUMN "users"."theme_preference" IS 'null can be interpreted as "unset", defaulting to the operators default theme'; diff --git a/coderd/database/migrations/create_migration.sh b/coderd/database/migrations/create_migration.sh index aac112c4292ca..d6c80926a31c4 100755 --- a/coderd/database/migrations/create_migration.sh +++ b/coderd/database/migrations/create_migration.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash # Usage: -# ./create_migration name of migration -# ./create_migration "name of migration" -# ./create_migration name_of_migration +# ./create_migration.sh name of migration +# ./create_migration.sh "name of migration" +# ./create_migration.sh name_of_migration set -euo pipefail @@ -27,7 +27,7 @@ CREATE TYPE new_logintype AS ENUM ( ALTER TABLE users ALTER COLUMN login_type DROP DEFAULT, -- if the column has a default, it must be dropped first - ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype), -- converts the old enum until the new enum using text as an intermediary + ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype), -- converts the old enum into the new enum using text as an intermediary ALTER COLUMN login_type SET DEFAULT 'password'::new_logintype; -- re-add the default using the new enum DROP TYPE login_type; From dd15c1f970d5727ca18a43e1fd3fea5f9279f6c3 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Wed, 6 Dec 2023 18:27:25 +0000 Subject: [PATCH 2/7] `make gen` --- coderd/database/dump.sql | 5 ++- .../000174_add_user_theme_preference.up.sql | 2 +- coderd/database/models.go | 2 + coderd/database/queries.sql.go | 37 +++++++++++++------ docs/admin/audit-logs.md | 2 +- enterprise/audit/table.go | 1 + 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 2a439aad78144..5bbb5b85bfa3b 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -749,11 +749,14 @@ CREATE TABLE users ( avatar_url text, deleted boolean DEFAULT false NOT NULL, last_seen_at timestamp without time zone DEFAULT '0001-01-01 00:00:00'::timestamp without time zone NOT NULL, - quiet_hours_schedule text DEFAULT ''::text NOT NULL + quiet_hours_schedule text DEFAULT ''::text NOT NULL, + theme_preference text ); COMMENT ON COLUMN users.quiet_hours_schedule IS 'Daily (!) cron schedule (with optional CRON_TZ) signifying the start of the user''s quiet hours. If empty, the default quiet hours on the instance is used instead.'; +COMMENT ON COLUMN users.theme_preference IS 'null can be interpreted as "unset", falling back to the default theme'; + CREATE VIEW visible_users AS SELECT users.id, users.username, diff --git a/coderd/database/migrations/000174_add_user_theme_preference.up.sql b/coderd/database/migrations/000174_add_user_theme_preference.up.sql index fd651157c7668..4f5bcca78ec2f 100644 --- a/coderd/database/migrations/000174_add_user_theme_preference.up.sql +++ b/coderd/database/migrations/000174_add_user_theme_preference.up.sql @@ -1,3 +1,3 @@ ALTER TABLE users ADD COLUMN "theme_preference" text; -COMMENT ON COLUMN "users"."theme_preference" IS 'null can be interpreted as "unset", defaulting to the operators default theme'; +COMMENT ON COLUMN "users"."theme_preference" IS 'null can be interpreted as "unset", falling back to the default theme'; diff --git a/coderd/database/models.go b/coderd/database/models.go index c5b40c66f58ab..2eeba1389fbe5 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -2119,6 +2119,8 @@ type User struct { LastSeenAt time.Time `db:"last_seen_at" json:"last_seen_at"` // Daily (!) cron schedule (with optional CRON_TZ) signifying the start of the user's quiet hours. If empty, the default quiet hours on the instance is used instead. QuietHoursSchedule string `db:"quiet_hours_schedule" json:"quiet_hours_schedule"` + // null can be interpreted as "unset", falling back to the default theme + ThemePreference sql.NullString `db:"theme_preference" json:"theme_preference"` } type UserLink struct { diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index fb7b15cf26866..e7a2ff4b1a09e 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -1300,7 +1300,7 @@ func (q *sqlQuerier) DeleteGroupMembersByOrgAndUser(ctx context.Context, arg Del const getGroupMembers = `-- name: GetGroupMembers :many SELECT - users.id, users.email, users.username, users.hashed_password, users.created_at, users.updated_at, users.status, users.rbac_roles, users.login_type, users.avatar_url, users.deleted, users.last_seen_at, users.quiet_hours_schedule + users.id, users.email, users.username, users.hashed_password, users.created_at, users.updated_at, users.status, users.rbac_roles, users.login_type, users.avatar_url, users.deleted, users.last_seen_at, users.quiet_hours_schedule, users.theme_preference FROM users LEFT JOIN @@ -1347,6 +1347,7 @@ func (q *sqlQuerier) GetGroupMembers(ctx context.Context, groupID uuid.UUID) ([] &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ); err != nil { return nil, err } @@ -7046,7 +7047,7 @@ func (q *sqlQuerier) GetAuthorizationUserRoles(ctx context.Context, userID uuid. const getUserByEmailOrUsername = `-- name: GetUserByEmailOrUsername :one SELECT - id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule + id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference FROM users WHERE @@ -7078,13 +7079,14 @@ func (q *sqlQuerier) GetUserByEmailOrUsername(ctx context.Context, arg GetUserBy &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } const getUserByID = `-- name: GetUserByID :one SELECT - id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule + id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference FROM users WHERE @@ -7110,6 +7112,7 @@ func (q *sqlQuerier) GetUserByID(ctx context.Context, id uuid.UUID) (User, error &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } @@ -7132,7 +7135,7 @@ func (q *sqlQuerier) GetUserCount(ctx context.Context) (int64, error) { const getUsers = `-- name: GetUsers :many SELECT - id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, COUNT(*) OVER() AS count + id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference, COUNT(*) OVER() AS count FROM users WHERE @@ -7229,6 +7232,7 @@ type GetUsersRow struct { Deleted bool `db:"deleted" json:"deleted"` LastSeenAt time.Time `db:"last_seen_at" json:"last_seen_at"` QuietHoursSchedule string `db:"quiet_hours_schedule" json:"quiet_hours_schedule"` + ThemePreference sql.NullString `db:"theme_preference" json:"theme_preference"` Count int64 `db:"count" json:"count"` } @@ -7265,6 +7269,7 @@ func (q *sqlQuerier) GetUsers(ctx context.Context, arg GetUsersParams) ([]GetUse &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, &i.Count, ); err != nil { return nil, err @@ -7281,7 +7286,7 @@ func (q *sqlQuerier) GetUsers(ctx context.Context, arg GetUsersParams) ([]GetUse } const getUsersByIDs = `-- name: GetUsersByIDs :many -SELECT id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule FROM users WHERE id = ANY($1 :: uuid [ ]) +SELECT id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference FROM users WHERE id = ANY($1 :: uuid [ ]) ` // This shouldn't check for deleted, because it's frequently used @@ -7310,6 +7315,7 @@ func (q *sqlQuerier) GetUsersByIDs(ctx context.Context, ids []uuid.UUID) ([]User &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ); err != nil { return nil, err } @@ -7337,7 +7343,7 @@ INSERT INTO login_type ) VALUES - ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule + ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference ` type InsertUserParams struct { @@ -7377,6 +7383,7 @@ func (q *sqlQuerier) InsertUser(ctx context.Context, arg InsertUserParams) (User &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } @@ -7472,7 +7479,7 @@ SET last_seen_at = $2, updated_at = $3 WHERE - id = $1 RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule + id = $1 RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference ` type UpdateUserLastSeenAtParams struct { @@ -7498,6 +7505,7 @@ func (q *sqlQuerier) UpdateUserLastSeenAt(ctx context.Context, arg UpdateUserLas &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } @@ -7515,7 +7523,7 @@ SET '':: bytea END WHERE - id = $2 RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule + id = $2 RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference ` type UpdateUserLoginTypeParams struct { @@ -7540,6 +7548,7 @@ func (q *sqlQuerier) UpdateUserLoginType(ctx context.Context, arg UpdateUserLogi &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } @@ -7553,7 +7562,7 @@ SET avatar_url = $4, updated_at = $5 WHERE - id = $1 RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule + id = $1 RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference ` type UpdateUserProfileParams struct { @@ -7587,6 +7596,7 @@ func (q *sqlQuerier) UpdateUserProfile(ctx context.Context, arg UpdateUserProfil &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } @@ -7598,7 +7608,7 @@ SET quiet_hours_schedule = $2 WHERE id = $1 -RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule +RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference ` type UpdateUserQuietHoursScheduleParams struct { @@ -7623,6 +7633,7 @@ func (q *sqlQuerier) UpdateUserQuietHoursSchedule(ctx context.Context, arg Updat &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } @@ -7635,7 +7646,7 @@ SET rbac_roles = ARRAY(SELECT DISTINCT UNNEST($1 :: text[])) WHERE id = $2 -RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule +RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference ` type UpdateUserRolesParams struct { @@ -7660,6 +7671,7 @@ func (q *sqlQuerier) UpdateUserRoles(ctx context.Context, arg UpdateUserRolesPar &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } @@ -7671,7 +7683,7 @@ SET status = $2, updated_at = $3 WHERE - id = $1 RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule + id = $1 RETURNING id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, login_type, avatar_url, deleted, last_seen_at, quiet_hours_schedule, theme_preference ` type UpdateUserStatusParams struct { @@ -7697,6 +7709,7 @@ func (q *sqlQuerier) UpdateUserStatus(ctx context.Context, arg UpdateUserStatusP &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, ) return i, err } diff --git a/docs/admin/audit-logs.md b/docs/admin/audit-logs.md index 527134f88befb..50848cc833d45 100644 --- a/docs/admin/audit-logs.md +++ b/docs/admin/audit-logs.md @@ -18,7 +18,7 @@ We track the following resources: | License
create, delete |
FieldTracked
exptrue
idfalse
jwtfalse
uploaded_attrue
uuidtrue
| | Template
write, delete |
FieldTracked
active_version_idtrue
allow_user_autostarttrue
allow_user_autostoptrue
allow_user_cancel_workspace_jobstrue
autostart_block_days_of_weektrue
autostop_requirement_days_of_weektrue
autostop_requirement_weekstrue
created_atfalse
created_bytrue
created_by_avatar_urlfalse
created_by_usernamefalse
default_ttltrue
deletedfalse
deprecatedtrue
descriptiontrue
display_nametrue
failure_ttltrue
group_acltrue
icontrue
idtrue
max_ttltrue
nametrue
organization_idfalse
provisionertrue
require_active_versiontrue
time_til_dormanttrue
time_til_dormant_autodeletetrue
updated_atfalse
user_acltrue
| | TemplateVersion
create, write |
FieldTracked
archivedtrue
created_atfalse
created_bytrue
created_by_avatar_urlfalse
created_by_usernamefalse
external_auth_providersfalse
idtrue
job_idfalse
messagefalse
nametrue
organization_idfalse
readmetrue
template_idtrue
updated_atfalse
| -| User
create, write, delete |
FieldTracked
avatar_urlfalse
created_atfalse
deletedtrue
emailtrue
hashed_passwordtrue
idtrue
last_seen_atfalse
login_typetrue
quiet_hours_scheduletrue
rbac_rolestrue
statustrue
updated_atfalse
usernametrue
| +| User
create, write, delete |
FieldTracked
avatar_urlfalse
created_atfalse
deletedtrue
emailtrue
hashed_passwordtrue
idtrue
last_seen_atfalse
login_typetrue
quiet_hours_scheduletrue
rbac_rolestrue
statustrue
theme_preferencefalse
updated_atfalse
usernametrue
| | Workspace
create, write, delete |
FieldTracked
automatic_updatestrue
autostart_scheduletrue
created_atfalse
deletedfalse
deleting_attrue
dormant_attrue
idtrue
last_used_atfalse
nametrue
organization_idfalse
owner_idtrue
template_idtrue
ttltrue
updated_atfalse
| | WorkspaceBuild
start, stop |
FieldTracked
build_numberfalse
created_atfalse
daily_costfalse
deadlinefalse
idfalse
initiator_by_avatar_urlfalse
initiator_by_usernamefalse
initiator_idfalse
job_idfalse
max_deadlinefalse
provisioner_statefalse
reasonfalse
template_version_idtrue
transitionfalse
updated_atfalse
workspace_idfalse
| | WorkspaceProxy
|
FieldTracked
created_attrue
deletedfalse
derp_enabledtrue
derp_onlytrue
display_nametrue
icontrue
idtrue
nametrue
region_idtrue
token_hashed_secrettrue
updated_atfalse
urltrue
versiontrue
wildcard_hostnametrue
| diff --git a/enterprise/audit/table.go b/enterprise/audit/table.go index dcd775cf4c1f3..fc5257110cf82 100644 --- a/enterprise/audit/table.go +++ b/enterprise/audit/table.go @@ -118,6 +118,7 @@ var auditableResourcesTypes = map[any]map[string]Action{ "last_seen_at": ActionIgnore, "deleted": ActionTrack, "quiet_hours_schedule": ActionTrack, + "theme_preference": ActionIgnore, }, &database.Workspace{}: { "id": ActionTrack, From 384cf9defef4f3731dd15b9c27c5bafa4dae93ac Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Wed, 6 Dec 2023 18:30:57 +0000 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=A7=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coderd/database/dump.sql | 2 +- .../database/migrations/000174_add_user_theme_preference.up.sql | 2 +- coderd/database/models.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 5bbb5b85bfa3b..53dbe413b7d22 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -755,7 +755,7 @@ CREATE TABLE users ( COMMENT ON COLUMN users.quiet_hours_schedule IS 'Daily (!) cron schedule (with optional CRON_TZ) signifying the start of the user''s quiet hours. If empty, the default quiet hours on the instance is used instead.'; -COMMENT ON COLUMN users.theme_preference IS 'null can be interpreted as "unset", falling back to the default theme'; +COMMENT ON COLUMN users.theme_preference IS 'null can be interpreted as "the user does not care", falling back to the default theme'; CREATE VIEW visible_users AS SELECT users.id, diff --git a/coderd/database/migrations/000174_add_user_theme_preference.up.sql b/coderd/database/migrations/000174_add_user_theme_preference.up.sql index 4f5bcca78ec2f..4bcef2680e6ea 100644 --- a/coderd/database/migrations/000174_add_user_theme_preference.up.sql +++ b/coderd/database/migrations/000174_add_user_theme_preference.up.sql @@ -1,3 +1,3 @@ ALTER TABLE users ADD COLUMN "theme_preference" text; -COMMENT ON COLUMN "users"."theme_preference" IS 'null can be interpreted as "unset", falling back to the default theme'; +COMMENT ON COLUMN "users"."theme_preference" IS 'null can be interpreted as "the user does not care", falling back to the default theme'; diff --git a/coderd/database/models.go b/coderd/database/models.go index 2eeba1389fbe5..6e852aa18b80e 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -2119,7 +2119,7 @@ type User struct { LastSeenAt time.Time `db:"last_seen_at" json:"last_seen_at"` // Daily (!) cron schedule (with optional CRON_TZ) signifying the start of the user's quiet hours. If empty, the default quiet hours on the instance is used instead. QuietHoursSchedule string `db:"quiet_hours_schedule" json:"quiet_hours_schedule"` - // null can be interpreted as "unset", falling back to the default theme + // null can be interpreted as "the user does not care", falling back to the default theme ThemePreference sql.NullString `db:"theme_preference" json:"theme_preference"` } From 1b6fc9e8b1dbe98dda4ae6e4eadf5a74d2397525 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Wed, 6 Dec 2023 20:49:08 +0000 Subject: [PATCH 4/7] huhu --- coderd/database/modelmethods.go | 25 +++++++++++++------------ coderd/database/modelqueries.go | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/coderd/database/modelmethods.go b/coderd/database/modelmethods.go index ed5bf76b784d7..8d15af65aada1 100644 --- a/coderd/database/modelmethods.go +++ b/coderd/database/modelmethods.go @@ -332,18 +332,19 @@ func ConvertUserRows(rows []GetUsersRow) []User { users := make([]User, len(rows)) for i, r := range rows { users[i] = User{ - ID: r.ID, - Email: r.Email, - Username: r.Username, - HashedPassword: r.HashedPassword, - CreatedAt: r.CreatedAt, - UpdatedAt: r.UpdatedAt, - Status: r.Status, - RBACRoles: r.RBACRoles, - LoginType: r.LoginType, - AvatarURL: r.AvatarURL, - Deleted: r.Deleted, - LastSeenAt: r.LastSeenAt, + ID: r.ID, + Email: r.Email, + Username: r.Username, + HashedPassword: r.HashedPassword, + CreatedAt: r.CreatedAt, + UpdatedAt: r.UpdatedAt, + Status: r.Status, + RBACRoles: r.RBACRoles, + LoginType: r.LoginType, + AvatarURL: r.AvatarURL, + Deleted: r.Deleted, + LastSeenAt: r.LastSeenAt, + ThemePreference: r.ThemePreference, } } diff --git a/coderd/database/modelqueries.go b/coderd/database/modelqueries.go index a050997a17ba1..8a9f61c396131 100644 --- a/coderd/database/modelqueries.go +++ b/coderd/database/modelqueries.go @@ -316,6 +316,7 @@ func (q *sqlQuerier) GetAuthorizedUsers(ctx context.Context, arg GetUsersParams, &i.Deleted, &i.LastSeenAt, &i.QuietHoursSchedule, + &i.ThemePreference, &i.Count, ); err != nil { return nil, err From a6c7f373d7a6c43bdd3cb39ef0cc2c3a5be94088 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Wed, 6 Dec 2023 20:56:46 +0000 Subject: [PATCH 5/7] add down migration --- .../migrations/000174_add_user_theme_preference.down.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/coderd/database/migrations/000174_add_user_theme_preference.down.sql b/coderd/database/migrations/000174_add_user_theme_preference.down.sql index e69de29bb2d1d..159c5d9b1c422 100644 --- a/coderd/database/migrations/000174_add_user_theme_preference.down.sql +++ b/coderd/database/migrations/000174_add_user_theme_preference.down.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP COLUMN "theme_preference"; From b87e3d05c8c5312a89298caeffd7f538d292ba98 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 8 Dec 2023 21:35:52 +0000 Subject: [PATCH 6/7] `NOT NULL` --- coderd/database/dump.sql | 4 ++-- .../migrations/000174_add_user_theme_preference.up.sql | 4 ++-- coderd/database/models.go | 4 ++-- coderd/database/queries.sql.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 53dbe413b7d22..11754ec274b96 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -750,12 +750,12 @@ CREATE TABLE users ( deleted boolean DEFAULT false NOT NULL, last_seen_at timestamp without time zone DEFAULT '0001-01-01 00:00:00'::timestamp without time zone NOT NULL, quiet_hours_schedule text DEFAULT ''::text NOT NULL, - theme_preference text + theme_preference text DEFAULT ''::text NOT NULL ); COMMENT ON COLUMN users.quiet_hours_schedule IS 'Daily (!) cron schedule (with optional CRON_TZ) signifying the start of the user''s quiet hours. If empty, the default quiet hours on the instance is used instead.'; -COMMENT ON COLUMN users.theme_preference IS 'null can be interpreted as "the user does not care", falling back to the default theme'; +COMMENT ON COLUMN users.theme_preference IS '"" can be interpreted as "the user does not care", falling back to the default theme'; CREATE VIEW visible_users AS SELECT users.id, diff --git a/coderd/database/migrations/000174_add_user_theme_preference.up.sql b/coderd/database/migrations/000174_add_user_theme_preference.up.sql index 4bcef2680e6ea..cb1313823410b 100644 --- a/coderd/database/migrations/000174_add_user_theme_preference.up.sql +++ b/coderd/database/migrations/000174_add_user_theme_preference.up.sql @@ -1,3 +1,3 @@ -ALTER TABLE users ADD COLUMN "theme_preference" text; +ALTER TABLE users ADD COLUMN "theme_preference" text NOT NULL DEFAULT ''; -COMMENT ON COLUMN "users"."theme_preference" IS 'null can be interpreted as "the user does not care", falling back to the default theme'; +COMMENT ON COLUMN "users"."theme_preference" IS '"" can be interpreted as "the user does not care", falling back to the default theme'; diff --git a/coderd/database/models.go b/coderd/database/models.go index 6e852aa18b80e..de9af474f2cf6 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -2119,8 +2119,8 @@ type User struct { LastSeenAt time.Time `db:"last_seen_at" json:"last_seen_at"` // Daily (!) cron schedule (with optional CRON_TZ) signifying the start of the user's quiet hours. If empty, the default quiet hours on the instance is used instead. QuietHoursSchedule string `db:"quiet_hours_schedule" json:"quiet_hours_schedule"` - // null can be interpreted as "the user does not care", falling back to the default theme - ThemePreference sql.NullString `db:"theme_preference" json:"theme_preference"` + // "" can be interpreted as "the user does not care", falling back to the default theme + ThemePreference string `db:"theme_preference" json:"theme_preference"` } type UserLink struct { diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index e7a2ff4b1a09e..bc08eb0cf0515 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -7232,7 +7232,7 @@ type GetUsersRow struct { Deleted bool `db:"deleted" json:"deleted"` LastSeenAt time.Time `db:"last_seen_at" json:"last_seen_at"` QuietHoursSchedule string `db:"quiet_hours_schedule" json:"quiet_hours_schedule"` - ThemePreference sql.NullString `db:"theme_preference" json:"theme_preference"` + ThemePreference string `db:"theme_preference" json:"theme_preference"` Count int64 `db:"count" json:"count"` } From d5a1ea92fb28abe0776fdce8ff0c485cdc7d3c3f Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 8 Dec 2023 21:48:13 +0000 Subject: [PATCH 7/7] reorder --- ...ference.down.sql => 000175_add_user_theme_preference.down.sql} | 0 ..._preference.up.sql => 000175_add_user_theme_preference.up.sql} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename coderd/database/migrations/{000174_add_user_theme_preference.down.sql => 000175_add_user_theme_preference.down.sql} (100%) rename coderd/database/migrations/{000174_add_user_theme_preference.up.sql => 000175_add_user_theme_preference.up.sql} (100%) diff --git a/coderd/database/migrations/000174_add_user_theme_preference.down.sql b/coderd/database/migrations/000175_add_user_theme_preference.down.sql similarity index 100% rename from coderd/database/migrations/000174_add_user_theme_preference.down.sql rename to coderd/database/migrations/000175_add_user_theme_preference.down.sql diff --git a/coderd/database/migrations/000174_add_user_theme_preference.up.sql b/coderd/database/migrations/000175_add_user_theme_preference.up.sql similarity index 100% rename from coderd/database/migrations/000174_add_user_theme_preference.up.sql rename to coderd/database/migrations/000175_add_user_theme_preference.up.sql