mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +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]>
259 lines
7.4 KiB
Go
259 lines
7.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: operations.sql
|
|
|
|
package sqlcdb
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const listActiveOperationDeployments = `-- name: ListActiveOperationDeployments :many
|
|
SELECT d.id, d.service_id, s.name AS service_name, p.name AS project_name, d.status,
|
|
COALESCE(d.image_name, '') AS image, d.error, d.started_at, d.completed_at, d.created_at
|
|
FROM deployments d
|
|
JOIN services s ON s.id = d.service_id
|
|
JOIN projects p ON p.id = s.project_id
|
|
WHERE d.status IN ('queued','pending','building','deploying','rolling_back')
|
|
AND (p.is_approved OR p.owner_id = $1 OR $2::bool
|
|
OR EXISTS (SELECT 1 FROM project_members pm WHERE pm.project_id = p.id AND pm.user_id = $1))
|
|
ORDER BY d.created_at ASC
|
|
`
|
|
|
|
type ListActiveOperationDeploymentsParams struct {
|
|
OwnerID uuid.UUID `json:"owner_id"`
|
|
Column2 bool `json:"column_2"`
|
|
}
|
|
|
|
type ListActiveOperationDeploymentsRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
ServiceName string `json:"service_name"`
|
|
ProjectName string `json:"project_name"`
|
|
Status sql.NullString `json:"status"`
|
|
Image string `json:"image"`
|
|
Error sql.NullString `json:"error"`
|
|
StartedAt sql.NullTime `json:"started_at"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) ListActiveOperationDeployments(ctx context.Context, arg ListActiveOperationDeploymentsParams) ([]ListActiveOperationDeploymentsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listActiveOperationDeployments, arg.OwnerID, arg.Column2)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListActiveOperationDeploymentsRow{}
|
|
for rows.Next() {
|
|
var i ListActiveOperationDeploymentsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ServiceID,
|
|
&i.ServiceName,
|
|
&i.ProjectName,
|
|
&i.Status,
|
|
&i.Image,
|
|
&i.Error,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&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 listRecentCronRuns = `-- name: ListRecentCronRuns :many
|
|
SELECT e.id, j.name AS job_name, j.schedule, e.status, e.started_at, e.finished_at, e.error
|
|
FROM cron_executions e
|
|
JOIN cron_jobs j ON j.id = e.cron_job_id
|
|
JOIN projects p ON p.id = j.project_id
|
|
WHERE e.started_at > NOW() - INTERVAL '24 hours'
|
|
AND (p.is_approved OR p.owner_id = $1 OR $2::bool
|
|
OR EXISTS (SELECT 1 FROM project_members pm WHERE pm.project_id = p.id AND pm.user_id = $1))
|
|
ORDER BY e.started_at DESC
|
|
LIMIT 30
|
|
`
|
|
|
|
type ListRecentCronRunsParams struct {
|
|
OwnerID uuid.UUID `json:"owner_id"`
|
|
Column2 bool `json:"column_2"`
|
|
}
|
|
|
|
type ListRecentCronRunsRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
JobName string `json:"job_name"`
|
|
Schedule string `json:"schedule"`
|
|
Status sql.NullString `json:"status"`
|
|
StartedAt time.Time `json:"started_at"`
|
|
FinishedAt sql.NullTime `json:"finished_at"`
|
|
Error sql.NullString `json:"error"`
|
|
}
|
|
|
|
func (q *Queries) ListRecentCronRuns(ctx context.Context, arg ListRecentCronRunsParams) ([]ListRecentCronRunsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listRecentCronRuns, arg.OwnerID, arg.Column2)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListRecentCronRunsRow{}
|
|
for rows.Next() {
|
|
var i ListRecentCronRunsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.JobName,
|
|
&i.Schedule,
|
|
&i.Status,
|
|
&i.StartedAt,
|
|
&i.FinishedAt,
|
|
&i.Error,
|
|
); 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 listRecentFailedDeployments = `-- name: ListRecentFailedDeployments :many
|
|
SELECT d.id, d.service_id, s.name AS service_name, p.name AS project_name, d.status,
|
|
COALESCE(d.image_name, '') AS image, d.error, d.started_at, d.completed_at, d.created_at
|
|
FROM deployments d
|
|
JOIN services s ON s.id = d.service_id
|
|
JOIN projects p ON p.id = s.project_id
|
|
WHERE d.status IN ('failed','cancelled','rolled_back')
|
|
AND d.updated_at > NOW() - INTERVAL '24 hours'
|
|
AND (p.is_approved OR p.owner_id = $1 OR $2::bool
|
|
OR EXISTS (SELECT 1 FROM project_members pm WHERE pm.project_id = p.id AND pm.user_id = $1))
|
|
ORDER BY d.updated_at DESC
|
|
LIMIT 20
|
|
`
|
|
|
|
type ListRecentFailedDeploymentsParams struct {
|
|
OwnerID uuid.UUID `json:"owner_id"`
|
|
Column2 bool `json:"column_2"`
|
|
}
|
|
|
|
type ListRecentFailedDeploymentsRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
ServiceName string `json:"service_name"`
|
|
ProjectName string `json:"project_name"`
|
|
Status sql.NullString `json:"status"`
|
|
Image string `json:"image"`
|
|
Error sql.NullString `json:"error"`
|
|
StartedAt sql.NullTime `json:"started_at"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) ListRecentFailedDeployments(ctx context.Context, arg ListRecentFailedDeploymentsParams) ([]ListRecentFailedDeploymentsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listRecentFailedDeployments, arg.OwnerID, arg.Column2)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListRecentFailedDeploymentsRow{}
|
|
for rows.Next() {
|
|
var i ListRecentFailedDeploymentsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ServiceID,
|
|
&i.ServiceName,
|
|
&i.ProjectName,
|
|
&i.Status,
|
|
&i.Image,
|
|
&i.Error,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&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 listRecentOperationBackups = `-- name: ListRecentOperationBackups :many
|
|
SELECT b.id, b.database_id, ds.name AS db_name, b.status, b.size, b.created_at, b.completed_at
|
|
FROM database_backups b
|
|
JOIN database_services ds ON ds.id = b.database_id
|
|
WHERE b.created_at > NOW() - INTERVAL '24 hours'
|
|
AND (ds.user_id = $1 OR $2::bool)
|
|
ORDER BY b.created_at DESC
|
|
LIMIT 20
|
|
`
|
|
|
|
type ListRecentOperationBackupsParams struct {
|
|
UserID string `json:"user_id"`
|
|
Column2 bool `json:"column_2"`
|
|
}
|
|
|
|
type ListRecentOperationBackupsRow struct {
|
|
ID string `json:"id"`
|
|
DatabaseID string `json:"database_id"`
|
|
DbName string `json:"db_name"`
|
|
Status string `json:"status"`
|
|
Size string `json:"size"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
}
|
|
|
|
func (q *Queries) ListRecentOperationBackups(ctx context.Context, arg ListRecentOperationBackupsParams) ([]ListRecentOperationBackupsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listRecentOperationBackups, arg.UserID, arg.Column2)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListRecentOperationBackupsRow{}
|
|
for rows.Next() {
|
|
var i ListRecentOperationBackupsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.DatabaseID,
|
|
&i.DbName,
|
|
&i.Status,
|
|
&i.Size,
|
|
&i.CreatedAt,
|
|
&i.CompletedAt,
|
|
); 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
|
|
}
|