chore: make "users"."avatar_url" NOT NULL (#11112)

This commit is contained in:
Kayla Washburn
2023-12-11 10:09:51 -07:00
committed by GitHub
parent 3e5d292135
commit 6775a86785
10 changed files with 55 additions and 48 deletions

View File

@ -120,7 +120,7 @@ func User(user database.User, organizationIDs []uuid.UUID) codersdk.User {
Status: codersdk.UserStatus(user.Status), Status: codersdk.UserStatus(user.Status),
OrganizationIDs: organizationIDs, OrganizationIDs: organizationIDs,
Roles: make([]codersdk.Role, 0, len(user.RBACRoles)), Roles: make([]codersdk.Role, 0, len(user.RBACRoles)),
AvatarURL: user.AvatarURL.String, AvatarURL: user.AvatarURL,
LoginType: codersdk.LoginType(user.LoginType), LoginType: codersdk.LoginType(user.LoginType),
} }

View File

@ -746,7 +746,7 @@ CREATE TABLE users (
status user_status DEFAULT 'dormant'::user_status NOT NULL, status user_status DEFAULT 'dormant'::user_status NOT NULL,
rbac_roles text[] DEFAULT '{}'::text[] NOT NULL, rbac_roles text[] DEFAULT '{}'::text[] NOT NULL,
login_type login_type DEFAULT 'password'::login_type NOT NULL, login_type login_type DEFAULT 'password'::login_type NOT NULL,
avatar_url text, avatar_url text DEFAULT ''::text NOT NULL,
deleted boolean DEFAULT false NOT NULL, 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, 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,

View File

@ -0,0 +1,3 @@
ALTER TABLE "users"
ALTER COLUMN "avatar_url" DROP NOT NULL,
ALTER COLUMN "avatar_url" DROP DEFAULT;

View File

@ -0,0 +1,7 @@
UPDATE "users"
SET "avatar_url" = ''
WHERE "avatar_url" IS NULL;
ALTER TABLE "users"
ALTER COLUMN "avatar_url" SET NOT NULL,
ALTER COLUMN "avatar_url" SET DEFAULT '';

View File

@ -1972,7 +1972,7 @@ type Template struct {
AutostartBlockDaysOfWeek int16 `db:"autostart_block_days_of_week" json:"autostart_block_days_of_week"` AutostartBlockDaysOfWeek int16 `db:"autostart_block_days_of_week" json:"autostart_block_days_of_week"`
RequireActiveVersion bool `db:"require_active_version" json:"require_active_version"` RequireActiveVersion bool `db:"require_active_version" json:"require_active_version"`
Deprecated string `db:"deprecated" json:"deprecated"` Deprecated string `db:"deprecated" json:"deprecated"`
CreatedByAvatarURL sql.NullString `db:"created_by_avatar_url" json:"created_by_avatar_url"` CreatedByAvatarURL string `db:"created_by_avatar_url" json:"created_by_avatar_url"`
CreatedByUsername string `db:"created_by_username" json:"created_by_username"` CreatedByUsername string `db:"created_by_username" json:"created_by_username"`
} }
@ -2017,20 +2017,20 @@ type TemplateTable struct {
// Joins in the username + avatar url of the created by user. // Joins in the username + avatar url of the created by user.
type TemplateVersion struct { type TemplateVersion struct {
ID uuid.UUID `db:"id" json:"id"` ID uuid.UUID `db:"id" json:"id"`
TemplateID uuid.NullUUID `db:"template_id" json:"template_id"` TemplateID uuid.NullUUID `db:"template_id" json:"template_id"`
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"` OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
CreatedAt time.Time `db:"created_at" json:"created_at"` CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
Name string `db:"name" json:"name"` Name string `db:"name" json:"name"`
Readme string `db:"readme" json:"readme"` Readme string `db:"readme" json:"readme"`
JobID uuid.UUID `db:"job_id" json:"job_id"` JobID uuid.UUID `db:"job_id" json:"job_id"`
CreatedBy uuid.UUID `db:"created_by" json:"created_by"` CreatedBy uuid.UUID `db:"created_by" json:"created_by"`
ExternalAuthProviders []string `db:"external_auth_providers" json:"external_auth_providers"` ExternalAuthProviders []string `db:"external_auth_providers" json:"external_auth_providers"`
Message string `db:"message" json:"message"` Message string `db:"message" json:"message"`
Archived bool `db:"archived" json:"archived"` Archived bool `db:"archived" json:"archived"`
CreatedByAvatarURL sql.NullString `db:"created_by_avatar_url" json:"created_by_avatar_url"` CreatedByAvatarURL string `db:"created_by_avatar_url" json:"created_by_avatar_url"`
CreatedByUsername string `db:"created_by_username" json:"created_by_username"` CreatedByUsername string `db:"created_by_username" json:"created_by_username"`
} }
type TemplateVersionParameter struct { type TemplateVersionParameter struct {
@ -2114,7 +2114,7 @@ type User struct {
Status UserStatus `db:"status" json:"status"` Status UserStatus `db:"status" json:"status"`
RBACRoles pq.StringArray `db:"rbac_roles" json:"rbac_roles"` RBACRoles pq.StringArray `db:"rbac_roles" json:"rbac_roles"`
LoginType LoginType `db:"login_type" json:"login_type"` LoginType LoginType `db:"login_type" json:"login_type"`
AvatarURL sql.NullString `db:"avatar_url" json:"avatar_url"` AvatarURL string `db:"avatar_url" json:"avatar_url"`
Deleted bool `db:"deleted" json:"deleted"` Deleted bool `db:"deleted" json:"deleted"`
LastSeenAt time.Time `db:"last_seen_at" json:"last_seen_at"` 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. // 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.
@ -2140,9 +2140,9 @@ type UserLink struct {
// Visible fields of users are allowed to be joined with other tables for including context of other resources. // Visible fields of users are allowed to be joined with other tables for including context of other resources.
type VisibleUser struct { type VisibleUser struct {
ID uuid.UUID `db:"id" json:"id"` ID uuid.UUID `db:"id" json:"id"`
Username string `db:"username" json:"username"` Username string `db:"username" json:"username"`
AvatarURL sql.NullString `db:"avatar_url" json:"avatar_url"` AvatarURL string `db:"avatar_url" json:"avatar_url"`
} }
type Workspace struct { type Workspace struct {
@ -2325,7 +2325,7 @@ type WorkspaceBuild struct {
Reason BuildReason `db:"reason" json:"reason"` Reason BuildReason `db:"reason" json:"reason"`
DailyCost int32 `db:"daily_cost" json:"daily_cost"` DailyCost int32 `db:"daily_cost" json:"daily_cost"`
MaxDeadline time.Time `db:"max_deadline" json:"max_deadline"` MaxDeadline time.Time `db:"max_deadline" json:"max_deadline"`
InitiatorByAvatarUrl sql.NullString `db:"initiator_by_avatar_url" json:"initiator_by_avatar_url"` InitiatorByAvatarUrl string `db:"initiator_by_avatar_url" json:"initiator_by_avatar_url"`
InitiatorByUsername string `db:"initiator_by_username" json:"initiator_by_username"` InitiatorByUsername string `db:"initiator_by_username" json:"initiator_by_username"`
} }

View File

@ -2325,11 +2325,11 @@ type GetUserActivityInsightsParams struct {
} }
type GetUserActivityInsightsRow struct { type GetUserActivityInsightsRow struct {
UserID uuid.UUID `db:"user_id" json:"user_id"` UserID uuid.UUID `db:"user_id" json:"user_id"`
Username string `db:"username" json:"username"` Username string `db:"username" json:"username"`
AvatarURL sql.NullString `db:"avatar_url" json:"avatar_url"` AvatarURL string `db:"avatar_url" json:"avatar_url"`
TemplateIDs []uuid.UUID `db:"template_ids" json:"template_ids"` TemplateIDs []uuid.UUID `db:"template_ids" json:"template_ids"`
UsageSeconds int64 `db:"usage_seconds" json:"usage_seconds"` UsageSeconds int64 `db:"usage_seconds" json:"usage_seconds"`
} }
// GetUserActivityInsights returns the ranking with top active users. // GetUserActivityInsights returns the ranking with top active users.
@ -2395,12 +2395,12 @@ type GetUserLatencyInsightsParams struct {
} }
type GetUserLatencyInsightsRow struct { type GetUserLatencyInsightsRow struct {
UserID uuid.UUID `db:"user_id" json:"user_id"` UserID uuid.UUID `db:"user_id" json:"user_id"`
Username string `db:"username" json:"username"` Username string `db:"username" json:"username"`
AvatarURL sql.NullString `db:"avatar_url" json:"avatar_url"` AvatarURL string `db:"avatar_url" json:"avatar_url"`
TemplateIDs []uuid.UUID `db:"template_ids" json:"template_ids"` TemplateIDs []uuid.UUID `db:"template_ids" json:"template_ids"`
WorkspaceConnectionLatency50 float64 `db:"workspace_connection_latency_50" json:"workspace_connection_latency_50"` WorkspaceConnectionLatency50 float64 `db:"workspace_connection_latency_50" json:"workspace_connection_latency_50"`
WorkspaceConnectionLatency95 float64 `db:"workspace_connection_latency_95" json:"workspace_connection_latency_95"` WorkspaceConnectionLatency95 float64 `db:"workspace_connection_latency_95" json:"workspace_connection_latency_95"`
} }
// GetUserLatencyInsights returns the median and 95th percentile connection // GetUserLatencyInsights returns the median and 95th percentile connection
@ -7228,7 +7228,7 @@ type GetUsersRow struct {
Status UserStatus `db:"status" json:"status"` Status UserStatus `db:"status" json:"status"`
RBACRoles pq.StringArray `db:"rbac_roles" json:"rbac_roles"` RBACRoles pq.StringArray `db:"rbac_roles" json:"rbac_roles"`
LoginType LoginType `db:"login_type" json:"login_type"` LoginType LoginType `db:"login_type" json:"login_type"`
AvatarURL sql.NullString `db:"avatar_url" json:"avatar_url"` AvatarURL string `db:"avatar_url" json:"avatar_url"`
Deleted bool `db:"deleted" json:"deleted"` Deleted bool `db:"deleted" json:"deleted"`
LastSeenAt time.Time `db:"last_seen_at" json:"last_seen_at"` LastSeenAt time.Time `db:"last_seen_at" json:"last_seen_at"`
QuietHoursSchedule string `db:"quiet_hours_schedule" json:"quiet_hours_schedule"` QuietHoursSchedule string `db:"quiet_hours_schedule" json:"quiet_hours_schedule"`
@ -7566,11 +7566,11 @@ WHERE
` `
type UpdateUserProfileParams struct { type UpdateUserProfileParams struct {
ID uuid.UUID `db:"id" json:"id"` ID uuid.UUID `db:"id" json:"id"`
Email string `db:"email" json:"email"` Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"` Username string `db:"username" json:"username"`
AvatarURL sql.NullString `db:"avatar_url" json:"avatar_url"` AvatarURL string `db:"avatar_url" json:"avatar_url"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
} }
func (q *sqlQuerier) UpdateUserProfile(ctx context.Context, arg UpdateUserProfileParams) (User, error) { func (q *sqlQuerier) UpdateUserProfile(ctx context.Context, arg UpdateUserProfileParams) (User, error) {

View File

@ -121,7 +121,7 @@ func (api *API) insightsUserActivity(rw http.ResponseWriter, r *http.Request) {
TemplateIDs: row.TemplateIDs, TemplateIDs: row.TemplateIDs,
UserID: row.UserID, UserID: row.UserID,
Username: row.Username, Username: row.Username,
AvatarURL: row.AvatarURL.String, AvatarURL: row.AvatarURL,
Seconds: row.UsageSeconds, Seconds: row.UsageSeconds,
}) })
} }
@ -208,7 +208,7 @@ func (api *API) insightsUserLatency(rw http.ResponseWriter, r *http.Request) {
TemplateIDs: row.TemplateIDs, TemplateIDs: row.TemplateIDs,
UserID: row.UserID, UserID: row.UserID,
Username: row.Username, Username: row.Username,
AvatarURL: row.AvatarURL.String, AvatarURL: row.AvatarURL,
LatencyMS: codersdk.ConnectionLatency{ LatencyMS: codersdk.ConnectionLatency{
P50: row.WorkspaceConnectionLatency50, P50: row.WorkspaceConnectionLatency50,
P95: row.WorkspaceConnectionLatency95, P95: row.WorkspaceConnectionLatency95,

View File

@ -1598,7 +1598,7 @@ func convertTemplateVersion(version database.TemplateVersion, job codersdk.Provi
CreatedBy: codersdk.MinimalUser{ CreatedBy: codersdk.MinimalUser{
ID: version.CreatedBy, ID: version.CreatedBy,
Username: version.CreatedByUsername, Username: version.CreatedByUsername,
AvatarURL: version.CreatedByAvatarURL.String, AvatarURL: version.CreatedByAvatarURL,
}, },
Archived: version.Archived, Archived: version.Archived,
Warnings: warnings, Warnings: warnings,

View File

@ -1473,11 +1473,8 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
} }
needsUpdate := false needsUpdate := false
if user.AvatarURL.String != params.AvatarURL { if user.AvatarURL != params.AvatarURL {
user.AvatarURL = sql.NullString{ user.AvatarURL = params.AvatarURL
String: params.AvatarURL,
Valid: true,
}
needsUpdate = true needsUpdate = true
} }

View File

@ -446,7 +446,7 @@ func convertUser(user database.User, organizationIDs []uuid.UUID) codersdk.User
Status: codersdk.UserStatus(user.Status), Status: codersdk.UserStatus(user.Status),
OrganizationIDs: organizationIDs, OrganizationIDs: organizationIDs,
Roles: make([]codersdk.Role, 0, len(user.RBACRoles)), Roles: make([]codersdk.Role, 0, len(user.RBACRoles)),
AvatarURL: user.AvatarURL.String, AvatarURL: user.AvatarURL,
LoginType: codersdk.LoginType(user.LoginType), LoginType: codersdk.LoginType(user.LoginType),
} }