Add user names support: add first_name/last_name to users table and regenerate database queries

This commit is contained in:
2026-01-23 21:27:08 -05:00
parent 7c89e9f214
commit f4e8c0d983
5 changed files with 74 additions and 18 deletions
+2
View File
@@ -64,4 +64,6 @@ type Users struct {
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
ScanFrequencyMinutes pgtype.Int4 `db:"scan_frequency_minutes" json:"scan_frequency_minutes"`
AutoScanEnabled pgtype.Bool `db:"auto_scan_enabled" json:"auto_scan_enabled"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
}
+1
View File
@@ -41,6 +41,7 @@ type Querier interface {
UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error
UpdateReadingProgress(ctx context.Context, arg UpdateReadingProgressParams) (ReadingProgress, error)
UpdateScanSettings(ctx context.Context, arg UpdateScanSettingsParams) error
UpdateUserProfile(ctx context.Context, arg UpdateUserProfileParams) error
UpdateUserTheme(ctx context.Context, arg UpdateUserThemeParams) error
UpdateUsername(ctx context.Context, arg UpdateUsernameParams) error
}
+56 -9
View File
@@ -129,15 +129,17 @@ func (q *Queries) CreateEbookRating(ctx context.Context, arg CreateEbookRatingPa
}
const CreateUser = `-- name: CreateUser :one
INSERT INTO users (email, username, password_hash, theme)
VALUES ($1, $2, $3, $4)
RETURNING id, email, username, theme, created_at, updated_at
INSERT INTO users (email, username, password_hash, first_name, last_name, theme)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, email, username, theme, first_name, last_name, created_at, updated_at
`
type CreateUserParams struct {
Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"`
PasswordHash string `db:"password_hash" json:"password_hash"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
Theme pgtype.Text `db:"theme" json:"theme"`
}
@@ -146,6 +148,8 @@ type CreateUserRow struct {
Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"`
Theme pgtype.Text `db:"theme" json:"theme"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
}
@@ -155,6 +159,8 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateU
arg.Email,
arg.Username,
arg.PasswordHash,
arg.FirstName,
arg.LastName,
arg.Theme,
)
var i CreateUserRow
@@ -163,6 +169,8 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateU
&i.Email,
&i.Username,
&i.Theme,
&i.FirstName,
&i.LastName,
&i.CreatedAt,
&i.UpdatedAt,
)
@@ -398,7 +406,7 @@ func (q *Queries) GetScanSettings(ctx context.Context, id pgtype.UUID) (GetScanS
}
const GetUser = `-- name: GetUser :one
SELECT id, email, username, theme, created_at, updated_at FROM users WHERE id = $1
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users WHERE id = $1
`
type GetUserRow struct {
@@ -406,6 +414,8 @@ type GetUserRow struct {
Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"`
Theme pgtype.Text `db:"theme" json:"theme"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
}
@@ -418,6 +428,8 @@ func (q *Queries) GetUser(ctx context.Context, id pgtype.UUID) (GetUserRow, erro
&i.Email,
&i.Username,
&i.Theme,
&i.FirstName,
&i.LastName,
&i.CreatedAt,
&i.UpdatedAt,
)
@@ -425,7 +437,7 @@ func (q *Queries) GetUser(ctx context.Context, id pgtype.UUID) (GetUserRow, erro
}
const GetUserByEmail = `-- name: GetUserByEmail :one
SELECT id, email, username, theme, created_at, updated_at FROM users WHERE email = $1
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users WHERE email = $1
`
type GetUserByEmailRow struct {
@@ -433,6 +445,8 @@ type GetUserByEmailRow struct {
Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"`
Theme pgtype.Text `db:"theme" json:"theme"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
}
@@ -445,6 +459,8 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEm
&i.Email,
&i.Username,
&i.Theme,
&i.FirstName,
&i.LastName,
&i.CreatedAt,
&i.UpdatedAt,
)
@@ -452,7 +468,7 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEm
}
const GetUserByEmailOrUsername = `-- name: GetUserByEmailOrUsername :one
SELECT id, email, username, theme, created_at, updated_at FROM users WHERE email = $1 OR username = $1
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users WHERE email = $1 OR username = $1
`
type GetUserByEmailOrUsernameRow struct {
@@ -460,6 +476,8 @@ type GetUserByEmailOrUsernameRow struct {
Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"`
Theme pgtype.Text `db:"theme" json:"theme"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
}
@@ -472,6 +490,8 @@ func (q *Queries) GetUserByEmailOrUsername(ctx context.Context, email string) (G
&i.Email,
&i.Username,
&i.Theme,
&i.FirstName,
&i.LastName,
&i.CreatedAt,
&i.UpdatedAt,
)
@@ -479,7 +499,7 @@ func (q *Queries) GetUserByEmailOrUsername(ctx context.Context, email string) (G
}
const GetUserByUsername = `-- name: GetUserByUsername :one
SELECT id, email, username, theme, created_at, updated_at FROM users WHERE username = $1
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users WHERE username = $1
`
type GetUserByUsernameRow struct {
@@ -487,6 +507,8 @@ type GetUserByUsernameRow struct {
Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"`
Theme pgtype.Text `db:"theme" json:"theme"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
}
@@ -499,6 +521,8 @@ func (q *Queries) GetUserByUsername(ctx context.Context, username string) (GetUs
&i.Email,
&i.Username,
&i.Theme,
&i.FirstName,
&i.LastName,
&i.CreatedAt,
&i.UpdatedAt,
)
@@ -535,7 +559,7 @@ func (q *Queries) GetUserEbookFolders(ctx context.Context, userID pgtype.UUID) (
}
const GetUserForLogin = `-- name: GetUserForLogin :one
SELECT id, email, username, password_hash, theme, created_at, updated_at FROM users WHERE email = $1 OR username = $1
SELECT id, email, username, password_hash, theme, first_name, last_name, created_at, updated_at FROM users WHERE email = $1 OR username = $1
`
type GetUserForLoginRow struct {
@@ -544,6 +568,8 @@ type GetUserForLoginRow struct {
Username string `db:"username" json:"username"`
PasswordHash string `db:"password_hash" json:"password_hash"`
Theme pgtype.Text `db:"theme" json:"theme"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
}
@@ -557,6 +583,8 @@ func (q *Queries) GetUserForLogin(ctx context.Context, email string) (GetUserFor
&i.Username,
&i.PasswordHash,
&i.Theme,
&i.FirstName,
&i.LastName,
&i.CreatedAt,
&i.UpdatedAt,
)
@@ -623,7 +651,7 @@ func (q *Queries) ListEbooks(ctx context.Context, arg ListEbooksParams) ([]Ebook
}
const ListUsers = `-- name: ListUsers :many
SELECT id, email, username, theme, created_at, updated_at FROM users ORDER BY created_at DESC
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users ORDER BY created_at DESC
`
type ListUsersRow struct {
@@ -631,6 +659,8 @@ type ListUsersRow struct {
Email string `db:"email" json:"email"`
Username string `db:"username" json:"username"`
Theme pgtype.Text `db:"theme" json:"theme"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
}
@@ -649,6 +679,8 @@ func (q *Queries) ListUsers(ctx context.Context) ([]ListUsersRow, error) {
&i.Email,
&i.Username,
&i.Theme,
&i.FirstName,
&i.LastName,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
@@ -845,6 +877,21 @@ func (q *Queries) UpdateScanSettings(ctx context.Context, arg UpdateScanSettings
return err
}
const UpdateUserProfile = `-- name: UpdateUserProfile :exec
UPDATE users SET first_name = $2, last_name = $3, updated_at = NOW() WHERE id = $1
`
type UpdateUserProfileParams struct {
ID pgtype.UUID `db:"id" json:"id"`
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
}
func (q *Queries) UpdateUserProfile(ctx context.Context, arg UpdateUserProfileParams) error {
_, err := q.db.Exec(ctx, UpdateUserProfile, arg.ID, arg.FirstName, arg.LastName)
return err
}
const UpdateUserTheme = `-- name: UpdateUserTheme :exec
UPDATE users SET theme = $2, updated_at = NOW() WHERE id = $1
`
+12 -9
View File
@@ -1,28 +1,28 @@
-- name: CreateUser :one
INSERT INTO users (email, username, password_hash, theme)
VALUES ($1, $2, $3, $4)
RETURNING id, email, username, theme, created_at, updated_at;
INSERT INTO users (email, username, password_hash, first_name, last_name, theme)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, email, username, theme, first_name, last_name, created_at, updated_at;
-- name: GetUserByEmail :one
SELECT id, email, username, theme, created_at, updated_at FROM users WHERE email = $1;
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users WHERE email = $1;
-- name: GetUserByUsername :one
SELECT id, email, username, theme, created_at, updated_at FROM users WHERE username = $1;
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users WHERE username = $1;
-- name: GetUserByEmailOrUsername :one
SELECT id, email, username, theme, created_at, updated_at FROM users WHERE email = $1 OR username = $1;
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users WHERE email = $1 OR username = $1;
-- name: GetUserForLogin :one
SELECT id, email, username, password_hash, theme, created_at, updated_at FROM users WHERE email = $1 OR username = $1;
SELECT id, email, username, password_hash, theme, first_name, last_name, created_at, updated_at FROM users WHERE email = $1 OR username = $1;
-- name: GetUser :one
SELECT id, email, username, theme, created_at, updated_at FROM users WHERE id = $1;
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users WHERE id = $1;
-- name: GetUserPasswordHash :one
SELECT password_hash FROM users WHERE id = $1;
-- name: ListUsers :many
SELECT id, email, username, theme, created_at, updated_at FROM users ORDER BY created_at DESC;
SELECT id, email, username, theme, first_name, last_name, created_at, updated_at FROM users ORDER BY created_at DESC;
-- name: GetEbook :one
SELECT * FROM ebooks WHERE id = $1;
@@ -75,6 +75,9 @@ DELETE FROM reading_progress WHERE ebook_id = $1 AND user_id = $2;
-- name: UpdateUserTheme :exec
UPDATE users SET theme = $2, updated_at = NOW() WHERE id = $1;
-- name: UpdateUserProfile :exec
UPDATE users SET first_name = $2, last_name = $3, updated_at = NOW() WHERE id = $1;
-- name: UpdateUsername :exec
UPDATE users SET username = $2, updated_at = NOW() WHERE id = $1;
+3
View File
@@ -0,0 +1,3 @@
-- Add first and last name to users table
ALTER TABLE users ADD COLUMN first_name VARCHAR(255);
ALTER TABLE users ADD COLUMN last_name VARCHAR(255);