mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +00:00
refactor(db): port operations, settings, audit, and misc metadata to sqlc (#84)
* 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]>
This commit is contained in:
1 parent
66301bb68a
commit
0dc5857b5f
45 files changed
+3272
-689
No files matched your search
@@ -0,0 +1,218 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: audit.sql
|
||||
|
||||
package sqlcdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/sqlc-dev/pqtype"
|
||||
)
|
||||
|
||||
const insertAuditLog = `-- name: InsertAuditLog :exec
|
||||
INSERT INTO audit_logs (id, user_id, resource, resource_id, action, details, severity, category, label, created_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
`
|
||||
|
||||
type InsertAuditLogParams struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
UserID uuid.NullUUID `json:"user_id"`
|
||||
Resource string `json:"resource"`
|
||||
ResourceID uuid.NullUUID `json:"resource_id"`
|
||||
Action string `json:"action"`
|
||||
Details pqtype.NullRawMessage `json:"details"`
|
||||
Severity string `json:"severity"`
|
||||
Category string `json:"category"`
|
||||
Label string `json:"label"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertAuditLog(ctx context.Context, arg InsertAuditLogParams) error {
|
||||
_, err := q.db.ExecContext(ctx, insertAuditLog,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Resource,
|
||||
arg.ResourceID,
|
||||
arg.Action,
|
||||
arg.Details,
|
||||
arg.Severity,
|
||||
arg.Category,
|
||||
arg.Label,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertAuditLogWithRequest = `-- name: InsertAuditLogWithRequest :exec
|
||||
INSERT INTO audit_logs (id, user_id, resource, resource_id, action, details, ip_address, user_agent, severity, category, label, created_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7::inet, $8, $9, $10, $11, $12)
|
||||
`
|
||||
|
||||
type InsertAuditLogWithRequestParams struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
UserID uuid.NullUUID `json:"user_id"`
|
||||
Resource string `json:"resource"`
|
||||
ResourceID uuid.NullUUID `json:"resource_id"`
|
||||
Action string `json:"action"`
|
||||
Column6 json.RawMessage `json:"column_6"`
|
||||
Column7 pqtype.Inet `json:"column_7"`
|
||||
UserAgent sql.NullString `json:"user_agent"`
|
||||
Severity string `json:"severity"`
|
||||
Category string `json:"category"`
|
||||
Label string `json:"label"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertAuditLogWithRequest(ctx context.Context, arg InsertAuditLogWithRequestParams) error {
|
||||
_, err := q.db.ExecContext(ctx, insertAuditLogWithRequest,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Resource,
|
||||
arg.ResourceID,
|
||||
arg.Action,
|
||||
arg.Column6,
|
||||
arg.Column7,
|
||||
arg.UserAgent,
|
||||
arg.Severity,
|
||||
arg.Category,
|
||||
arg.Label,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const listAuditBackfillBatch = `-- name: ListAuditBackfillBatch :many
|
||||
SELECT id::text, resource, action FROM audit_logs
|
||||
WHERE label = '' AND id > $1::uuid ORDER BY id LIMIT 500
|
||||
`
|
||||
|
||||
type ListAuditBackfillBatchRow struct {
|
||||
ID string `json:"id"`
|
||||
Resource string `json:"resource"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListAuditBackfillBatch(ctx context.Context, dollar_1 uuid.UUID) ([]ListAuditBackfillBatchRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listAuditBackfillBatch, dollar_1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListAuditBackfillBatchRow{}
|
||||
for rows.Next() {
|
||||
var i ListAuditBackfillBatchRow
|
||||
if err := rows.Scan(&i.ID, &i.Resource, &i.Action); 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 listResourceAuditLogs = `-- name: ListResourceAuditLogs :many
|
||||
SELECT id, COALESCE(user_id::text, '')::text AS user_id, resource,
|
||||
COALESCE(resource_id::text, '')::text AS resource_id, action,
|
||||
COALESCE(details::text, '{}')::text AS details,
|
||||
COALESCE(ip_address::text, '')::text AS ip_address,
|
||||
COALESCE(user_agent, '') AS user_agent, created_at
|
||||
FROM audit_logs
|
||||
WHERE user_id::text = $1 AND resource = $2 AND resource_id::text = $3
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 100
|
||||
`
|
||||
|
||||
type ListResourceAuditLogsParams struct {
|
||||
UserID uuid.NullUUID `json:"user_id"`
|
||||
Resource string `json:"resource"`
|
||||
ResourceID uuid.NullUUID `json:"resource_id"`
|
||||
}
|
||||
|
||||
type ListResourceAuditLogsRow struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
Resource string `json:"resource"`
|
||||
ResourceID string `json:"resource_id"`
|
||||
Action string `json:"action"`
|
||||
Details string `json:"details"`
|
||||
IpAddress string `json:"ip_address"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListResourceAuditLogs(ctx context.Context, arg ListResourceAuditLogsParams) ([]ListResourceAuditLogsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listResourceAuditLogs, arg.UserID, arg.Resource, arg.ResourceID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListResourceAuditLogsRow{}
|
||||
for rows.Next() {
|
||||
var i ListResourceAuditLogsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.Resource,
|
||||
&i.ResourceID,
|
||||
&i.Action,
|
||||
&i.Details,
|
||||
&i.IpAddress,
|
||||
&i.UserAgent,
|
||||
&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 pruneAuditLogs = `-- name: PruneAuditLogs :execrows
|
||||
DELETE FROM audit_logs WHERE created_at < NOW() - ($1::int * INTERVAL '1 day')
|
||||
`
|
||||
|
||||
func (q *Queries) PruneAuditLogs(ctx context.Context, dollar_1 int32) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, pruneAuditLogs, dollar_1)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const setAuditLogMetadata = `-- name: SetAuditLogMetadata :exec
|
||||
UPDATE audit_logs SET severity = $1, category = $2, label = $3 WHERE id = $4::uuid
|
||||
`
|
||||
|
||||
type SetAuditLogMetadataParams struct {
|
||||
Severity string `json:"severity"`
|
||||
Category string `json:"category"`
|
||||
Label string `json:"label"`
|
||||
Column4 uuid.UUID `json:"column_4"`
|
||||
}
|
||||
|
||||
func (q *Queries) SetAuditLogMetadata(ctx context.Context, arg SetAuditLogMetadataParams) error {
|
||||
_, err := q.db.ExecContext(ctx, setAuditLogMetadata,
|
||||
arg.Severity,
|
||||
arg.Category,
|
||||
arg.Label,
|
||||
arg.Column4,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user