mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
* refactor(db): port operations, settings, audit, activity, and misc service metadata to sqlc Covers the cross-cutting surface: operations board reads, app settings, notification producers, activity/audit inserts, builds upsert/cancel, git clone credential resolution, invites, environments, registry auth, project/service variables, HA resolver, boot sweeps, and admin user ops. Dynamic filtered lists and Better Auth table probes stay raw by design. Authored By: TDvorak <[email protected]> * refactor(db): port apwhy gateway handlers and proxy data plane to sqlc Final tranche — every static call site now uses generated queries. Raw SQL remains only where the statement is assembled at runtime (filtered lists, sparse updates, admin count closure) or probes Better Auth's auth_users table, which lives outside the local schema. Authored By: TDvorak <[email protected]>
336 lines
8.7 KiB
Go
336 lines
8.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: auth.sql
|
|
|
|
package sqlcdb
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const countUsers = `-- name: CountUsers :one
|
|
SELECT COUNT(*) FROM users
|
|
`
|
|
|
|
func (q *Queries) CountUsers(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countUsers)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countUsersByEmail = `-- name: CountUsersByEmail :one
|
|
SELECT COUNT(*) FROM users WHERE email = $1
|
|
`
|
|
|
|
func (q *Queries) CountUsersByEmail(ctx context.Context, email string) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countUsersByEmail, email)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const getAdminUserInfo = `-- name: GetAdminUserInfo :one
|
|
SELECT email, COALESCE(name, '') AS name, is_admin
|
|
FROM users WHERE id = $1
|
|
`
|
|
|
|
type GetAdminUserInfoRow struct {
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
}
|
|
|
|
func (q *Queries) GetAdminUserInfo(ctx context.Context, id uuid.UUID) (GetAdminUserInfoRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getAdminUserInfo, id)
|
|
var i GetAdminUserInfoRow
|
|
err := row.Scan(&i.Email, &i.Name, &i.IsAdmin)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByEmailForAuth = `-- name: GetUserByEmailForAuth :one
|
|
SELECT id, email, password_hash, name, COALESCE(avatar_url, '') AS avatar_url, is_admin, created_at
|
|
FROM users WHERE email = $1
|
|
`
|
|
|
|
type GetUserByEmailForAuthRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Name string `json:"name"`
|
|
AvatarUrl string `json:"avatar_url"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) GetUserByEmailForAuth(ctx context.Context, email string) (GetUserByEmailForAuthRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByEmailForAuth, email)
|
|
var i GetUserByEmailForAuthRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.PasswordHash,
|
|
&i.Name,
|
|
&i.AvatarUrl,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByID = `-- name: GetUserByID :one
|
|
SELECT id, email, name, COALESCE(avatar_url, '') AS avatar_url, is_admin, created_at
|
|
FROM users WHERE id = $1
|
|
`
|
|
|
|
type GetUserByIDRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
AvatarUrl string `json:"avatar_url"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id uuid.UUID) (GetUserByIDRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByID, id)
|
|
var i GetUserByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.Name,
|
|
&i.AvatarUrl,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertUser = `-- name: InsertUser :one
|
|
INSERT INTO users (email, password_hash, name)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING id, email, name, COALESCE(avatar_url, '') AS avatar_url, is_admin, created_at
|
|
`
|
|
|
|
type InsertUserParams struct {
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type InsertUserRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
AvatarUrl string `json:"avatar_url"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (InsertUserRow, error) {
|
|
row := q.db.QueryRowContext(ctx, insertUser, arg.Email, arg.PasswordHash, arg.Name)
|
|
var i InsertUserRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.Name,
|
|
&i.AvatarUrl,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertUserAdmin = `-- name: InsertUserAdmin :one
|
|
INSERT INTO users (email, password_hash, name, is_admin)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING id, email, name, COALESCE(avatar_url, '') AS avatar_url, is_admin, created_at
|
|
`
|
|
|
|
type InsertUserAdminParams struct {
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Name string `json:"name"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
}
|
|
|
|
type InsertUserAdminRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
AvatarUrl string `json:"avatar_url"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) InsertUserAdmin(ctx context.Context, arg InsertUserAdminParams) (InsertUserAdminRow, error) {
|
|
row := q.db.QueryRowContext(ctx, insertUserAdmin,
|
|
arg.Email,
|
|
arg.PasswordHash,
|
|
arg.Name,
|
|
arg.IsAdmin,
|
|
)
|
|
var i InsertUserAdminRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.Name,
|
|
&i.AvatarUrl,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listAdminUsers = `-- name: ListAdminUsers :many
|
|
SELECT id, email, name, COALESCE(avatar_url, '') AS avatar_url, is_admin,
|
|
COALESCE(to_char(created_at, 'YYYY-MM-DD"T"HH24:MI:SS"Z"'), '')::text AS created_at
|
|
FROM users
|
|
ORDER BY created_at ASC
|
|
`
|
|
|
|
type ListAdminUsersRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
AvatarUrl string `json:"avatar_url"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) ListAdminUsers(ctx context.Context) ([]ListAdminUsersRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listAdminUsers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListAdminUsersRow{}
|
|
for rows.Next() {
|
|
var i ListAdminUsersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.Name,
|
|
&i.AvatarUrl,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const setUserAdmin = `-- name: SetUserAdmin :execrows
|
|
UPDATE users SET is_admin = $1, updated_at = NOW() WHERE id = $2
|
|
`
|
|
|
|
type SetUserAdminParams struct {
|
|
IsAdmin bool `json:"is_admin"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error) {
|
|
result, err := q.db.ExecContext(ctx, setUserAdmin, arg.IsAdmin, arg.ID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected()
|
|
}
|
|
|
|
const updateUserProfile = `-- name: UpdateUserProfile :exec
|
|
UPDATE users
|
|
SET name = COALESCE($1::varchar, name), avatar_url = COALESCE($2::varchar, avatar_url)
|
|
WHERE id = $3
|
|
`
|
|
|
|
type UpdateUserProfileParams struct {
|
|
Column1 string `json:"column_1"`
|
|
Column2 string `json:"column_2"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserProfile(ctx context.Context, arg UpdateUserProfileParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateUserProfile, arg.Column1, arg.Column2, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const upsertAdminUser = `-- name: UpsertAdminUser :one
|
|
INSERT INTO users (email, password_hash, name, is_admin)
|
|
VALUES ($1, $2, $3, true)
|
|
ON CONFLICT (email) DO UPDATE
|
|
SET is_admin = true, updated_at = NOW()
|
|
RETURNING id
|
|
`
|
|
|
|
type UpsertAdminUserParams struct {
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func (q *Queries) UpsertAdminUser(ctx context.Context, arg UpsertAdminUserParams) (uuid.UUID, error) {
|
|
row := q.db.QueryRowContext(ctx, upsertAdminUser, arg.Email, arg.PasswordHash, arg.Name)
|
|
var id uuid.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const upsertLocalUser = `-- name: UpsertLocalUser :one
|
|
INSERT INTO users (email, password_hash, name, avatar_url, is_admin)
|
|
VALUES ($1, $2, $3, NULLIF($4::varchar, ''), $5)
|
|
ON CONFLICT (email) DO UPDATE
|
|
SET name = EXCLUDED.name,
|
|
avatar_url = COALESCE(EXCLUDED.avatar_url, users.avatar_url),
|
|
updated_at = NOW()
|
|
RETURNING id, email, name, COALESCE(avatar_url, '') AS avatar_url, is_admin, created_at
|
|
`
|
|
|
|
type UpsertLocalUserParams struct {
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Name string `json:"name"`
|
|
Column4 string `json:"column_4"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
}
|
|
|
|
type UpsertLocalUserRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
AvatarUrl string `json:"avatar_url"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) UpsertLocalUser(ctx context.Context, arg UpsertLocalUserParams) (UpsertLocalUserRow, error) {
|
|
row := q.db.QueryRowContext(ctx, upsertLocalUser,
|
|
arg.Email,
|
|
arg.PasswordHash,
|
|
arg.Name,
|
|
arg.Column4,
|
|
arg.IsAdmin,
|
|
)
|
|
var i UpsertLocalUserRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.Name,
|
|
&i.AvatarUrl,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|