mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +00:00
Tranche 4: all 32 raw sites in deployments.go — paginated service list, the accessible-feed joins (owner/member/admin/approved), service+owner load, deployment insert, status transitions (fail/complete/set), the 10-field progress sync, cancel access check, rollback reads/inserts, and the published_port reuse read. The shared serviceForDeployFromRow mapper now feeds both the preview and deployments loaders. Live test covers the full lifecycle: insert, list, access join, feed predicate, queued → deployed sync, failed transition. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
537 lines
16 KiB
Go
537 lines
16 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: deployments.sql
|
|
|
|
package sqlcdb
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const completeDeployment = `-- name: CompleteDeployment :exec
|
|
UPDATE deployments
|
|
SET status = $1, error = $2, completed_at = $3, updated_at = $3
|
|
WHERE id = $4
|
|
`
|
|
|
|
type CompleteDeploymentParams struct {
|
|
Status sql.NullString `json:"status"`
|
|
Error sql.NullString `json:"error"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) CompleteDeployment(ctx context.Context, arg CompleteDeploymentParams) error {
|
|
_, err := q.db.ExecContext(ctx, completeDeployment,
|
|
arg.Status,
|
|
arg.Error,
|
|
arg.CompletedAt,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const countAccessibleDeployments = `-- name: CountAccessibleDeployments :one
|
|
SELECT COUNT(*)
|
|
FROM deployments d
|
|
JOIN services s ON s.id = d.service_id
|
|
JOIN projects p ON p.id = s.project_id
|
|
WHERE 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)
|
|
`
|
|
|
|
type CountAccessibleDeploymentsParams struct {
|
|
OwnerID uuid.UUID `json:"owner_id"`
|
|
Column2 bool `json:"column_2"`
|
|
}
|
|
|
|
func (q *Queries) CountAccessibleDeployments(ctx context.Context, arg CountAccessibleDeploymentsParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countAccessibleDeployments, arg.OwnerID, arg.Column2)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countDeploymentsForService = `-- name: CountDeploymentsForService :one
|
|
SELECT COUNT(*) FROM deployments WHERE service_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountDeploymentsForService(ctx context.Context, serviceID uuid.UUID) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countDeploymentsForService, serviceID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const failDeployment = `-- name: FailDeployment :exec
|
|
UPDATE deployments
|
|
SET status = 'failed', error = $1, completed_at = $2, updated_at = $2
|
|
WHERE id = $3
|
|
`
|
|
|
|
type FailDeploymentParams struct {
|
|
Error sql.NullString `json:"error"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) FailDeployment(ctx context.Context, arg FailDeploymentParams) error {
|
|
_, err := q.db.ExecContext(ctx, failDeployment, arg.Error, arg.CompletedAt, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const getDeploymentAccess = `-- name: GetDeploymentAccess :one
|
|
SELECT d.status, d.service_id, p.owner_id
|
|
FROM deployments d
|
|
JOIN services s ON d.service_id = s.id
|
|
JOIN projects p ON s.project_id = p.id
|
|
WHERE d.id = $1
|
|
`
|
|
|
|
type GetDeploymentAccessRow struct {
|
|
Status sql.NullString `json:"status"`
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
OwnerID uuid.UUID `json:"owner_id"`
|
|
}
|
|
|
|
func (q *Queries) GetDeploymentAccess(ctx context.Context, id uuid.UUID) (GetDeploymentAccessRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getDeploymentAccess, id)
|
|
var i GetDeploymentAccessRow
|
|
err := row.Scan(&i.Status, &i.ServiceID, &i.OwnerID)
|
|
return i, err
|
|
}
|
|
|
|
const getDeploymentForRollback = `-- name: GetDeploymentForRollback :one
|
|
SELECT d.id, d.service_id, d.commit_hash, d.status, d.image_name, d.image_tag,
|
|
d.build_log, d.runtime_log, d.error, d.started_at, d.completed_at,
|
|
d.created_at, d.updated_at, p.owner_id
|
|
FROM deployments d
|
|
JOIN services s ON d.service_id = s.id
|
|
JOIN projects p ON s.project_id = p.id
|
|
WHERE d.id = $1
|
|
`
|
|
|
|
type GetDeploymentForRollbackRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
CommitHash sql.NullString `json:"commit_hash"`
|
|
Status sql.NullString `json:"status"`
|
|
ImageName sql.NullString `json:"image_name"`
|
|
ImageTag sql.NullString `json:"image_tag"`
|
|
BuildLog sql.NullString `json:"build_log"`
|
|
RuntimeLog sql.NullString `json:"runtime_log"`
|
|
Error sql.NullString `json:"error"`
|
|
StartedAt sql.NullTime `json:"started_at"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
OwnerID uuid.UUID `json:"owner_id"`
|
|
}
|
|
|
|
func (q *Queries) GetDeploymentForRollback(ctx context.Context, id uuid.UUID) (GetDeploymentForRollbackRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getDeploymentForRollback, id)
|
|
var i GetDeploymentForRollbackRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ServiceID,
|
|
&i.CommitHash,
|
|
&i.Status,
|
|
&i.ImageName,
|
|
&i.ImageTag,
|
|
&i.BuildLog,
|
|
&i.RuntimeLog,
|
|
&i.Error,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.OwnerID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getDeploymentWithProject = `-- name: GetDeploymentWithProject :one
|
|
SELECT d.id, d.service_id, d.commit_hash, d.status, d.image_name, d.image_tag,
|
|
d.build_log, d.runtime_log, d.error, d.started_at, d.completed_at,
|
|
d.created_at, d.updated_at, p.id AS project_id
|
|
FROM deployments d
|
|
JOIN services s ON d.service_id = s.id
|
|
JOIN projects p ON s.project_id = p.id
|
|
WHERE d.id = $1
|
|
`
|
|
|
|
type GetDeploymentWithProjectRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
CommitHash sql.NullString `json:"commit_hash"`
|
|
Status sql.NullString `json:"status"`
|
|
ImageName sql.NullString `json:"image_name"`
|
|
ImageTag sql.NullString `json:"image_tag"`
|
|
BuildLog sql.NullString `json:"build_log"`
|
|
RuntimeLog sql.NullString `json:"runtime_log"`
|
|
Error sql.NullString `json:"error"`
|
|
StartedAt sql.NullTime `json:"started_at"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
}
|
|
|
|
func (q *Queries) GetDeploymentWithProject(ctx context.Context, id uuid.UUID) (GetDeploymentWithProjectRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getDeploymentWithProject, id)
|
|
var i GetDeploymentWithProjectRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ServiceID,
|
|
&i.CommitHash,
|
|
&i.Status,
|
|
&i.ImageName,
|
|
&i.ImageTag,
|
|
&i.BuildLog,
|
|
&i.RuntimeLog,
|
|
&i.Error,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ProjectID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getServiceForDeployWithOwner = `-- name: GetServiceForDeployWithOwner :one
|
|
SELECT s.id, s.project_id, s.name, s.type, s.status, s.image, s.command,
|
|
s.environment, s.git_repo, s.git_branch, s.build_path, s.cpu, s.memory,
|
|
COALESCE(s.replicas, 1) AS replicas, COALESCE(s.port, 0) AS port,
|
|
COALESCE(s.domain, '') AS domain, COALESCE(s.healthcheck_path, '') AS healthcheck_path,
|
|
COALESCE(s.restart_policy, 'unless-stopped') AS restart_policy,
|
|
COALESCE(s.builder, 'auto') AS builder, COALESCE(s.cpu_reserve, '') AS cpu_reserve,
|
|
COALESCE(s.memory_reserve, '') AS memory_reserve, COALESCE(s.static_build_cmd, '') AS static_build_cmd,
|
|
COALESCE(s.static_dir, '') AS static_dir,
|
|
s.created_at, s.updated_at, p.owner_id
|
|
FROM services s
|
|
JOIN projects p ON s.project_id = p.id
|
|
WHERE s.id = $1
|
|
`
|
|
|
|
type GetServiceForDeployWithOwnerRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
Name string `json:"name"`
|
|
Type sql.NullString `json:"type"`
|
|
Status sql.NullString `json:"status"`
|
|
Image sql.NullString `json:"image"`
|
|
Command sql.NullString `json:"command"`
|
|
Environment sql.NullString `json:"environment"`
|
|
GitRepo sql.NullString `json:"git_repo"`
|
|
GitBranch sql.NullString `json:"git_branch"`
|
|
BuildPath sql.NullString `json:"build_path"`
|
|
Cpu sql.NullString `json:"cpu"`
|
|
Memory sql.NullString `json:"memory"`
|
|
Replicas int32 `json:"replicas"`
|
|
Port int32 `json:"port"`
|
|
Domain string `json:"domain"`
|
|
HealthcheckPath string `json:"healthcheck_path"`
|
|
RestartPolicy string `json:"restart_policy"`
|
|
Builder string `json:"builder"`
|
|
CpuReserve string `json:"cpu_reserve"`
|
|
MemoryReserve string `json:"memory_reserve"`
|
|
StaticBuildCmd string `json:"static_build_cmd"`
|
|
StaticDir string `json:"static_dir"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
OwnerID uuid.UUID `json:"owner_id"`
|
|
}
|
|
|
|
func (q *Queries) GetServiceForDeployWithOwner(ctx context.Context, id uuid.UUID) (GetServiceForDeployWithOwnerRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getServiceForDeployWithOwner, id)
|
|
var i GetServiceForDeployWithOwnerRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Name,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.Image,
|
|
&i.Command,
|
|
&i.Environment,
|
|
&i.GitRepo,
|
|
&i.GitBranch,
|
|
&i.BuildPath,
|
|
&i.Cpu,
|
|
&i.Memory,
|
|
&i.Replicas,
|
|
&i.Port,
|
|
&i.Domain,
|
|
&i.HealthcheckPath,
|
|
&i.RestartPolicy,
|
|
&i.Builder,
|
|
&i.CpuReserve,
|
|
&i.MemoryReserve,
|
|
&i.StaticBuildCmd,
|
|
&i.StaticDir,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.OwnerID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getServicePublishedPort = `-- name: GetServicePublishedPort :one
|
|
SELECT published_port FROM services WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetServicePublishedPort(ctx context.Context, id uuid.UUID) (int32, error) {
|
|
row := q.db.QueryRowContext(ctx, getServicePublishedPort, id)
|
|
var published_port int32
|
|
err := row.Scan(&published_port)
|
|
return published_port, err
|
|
}
|
|
|
|
const insertDeployment = `-- name: InsertDeployment :exec
|
|
INSERT INTO deployments
|
|
(id, service_id, version, commit_hash, status, image_name, image_tag, created_at, updated_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
`
|
|
|
|
type InsertDeploymentParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
Version string `json:"version"`
|
|
CommitHash sql.NullString `json:"commit_hash"`
|
|
Status sql.NullString `json:"status"`
|
|
ImageName sql.NullString `json:"image_name"`
|
|
ImageTag sql.NullString `json:"image_tag"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) InsertDeployment(ctx context.Context, arg InsertDeploymentParams) error {
|
|
_, err := q.db.ExecContext(ctx, insertDeployment,
|
|
arg.ID,
|
|
arg.ServiceID,
|
|
arg.Version,
|
|
arg.CommitHash,
|
|
arg.Status,
|
|
arg.ImageName,
|
|
arg.ImageTag,
|
|
arg.CreatedAt,
|
|
arg.UpdatedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const listDeploymentsForService = `-- name: ListDeploymentsForService :many
|
|
SELECT id, service_id, commit_hash, status, image_name, image_tag,
|
|
build_log, runtime_log, error, started_at, completed_at, created_at, updated_at
|
|
FROM deployments
|
|
WHERE service_id = $1
|
|
ORDER BY created_at DESC
|
|
LIMIT $2 OFFSET $3
|
|
`
|
|
|
|
type ListDeploymentsForServiceParams struct {
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListDeploymentsForServiceRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
CommitHash sql.NullString `json:"commit_hash"`
|
|
Status sql.NullString `json:"status"`
|
|
ImageName sql.NullString `json:"image_name"`
|
|
ImageTag sql.NullString `json:"image_tag"`
|
|
BuildLog sql.NullString `json:"build_log"`
|
|
RuntimeLog sql.NullString `json:"runtime_log"`
|
|
Error sql.NullString `json:"error"`
|
|
StartedAt sql.NullTime `json:"started_at"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) ListDeploymentsForService(ctx context.Context, arg ListDeploymentsForServiceParams) ([]ListDeploymentsForServiceRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listDeploymentsForService, arg.ServiceID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListDeploymentsForServiceRow{}
|
|
for rows.Next() {
|
|
var i ListDeploymentsForServiceRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ServiceID,
|
|
&i.CommitHash,
|
|
&i.Status,
|
|
&i.ImageName,
|
|
&i.ImageTag,
|
|
&i.BuildLog,
|
|
&i.RuntimeLog,
|
|
&i.Error,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); 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 listRecentAccessibleDeployments = `-- name: ListRecentAccessibleDeployments :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_name, 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 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 DESC
|
|
LIMIT $3 OFFSET $4
|
|
`
|
|
|
|
type ListRecentAccessibleDeploymentsParams struct {
|
|
OwnerID uuid.UUID `json:"owner_id"`
|
|
Column2 bool `json:"column_2"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListRecentAccessibleDeploymentsRow 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"`
|
|
ImageName string `json:"image_name"`
|
|
StartedAt sql.NullTime `json:"started_at"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) ListRecentAccessibleDeployments(ctx context.Context, arg ListRecentAccessibleDeploymentsParams) ([]ListRecentAccessibleDeploymentsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listRecentAccessibleDeployments,
|
|
arg.OwnerID,
|
|
arg.Column2,
|
|
arg.Limit,
|
|
arg.Offset,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListRecentAccessibleDeploymentsRow{}
|
|
for rows.Next() {
|
|
var i ListRecentAccessibleDeploymentsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ServiceID,
|
|
&i.ServiceName,
|
|
&i.ProjectName,
|
|
&i.Status,
|
|
&i.ImageName,
|
|
&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 setDeploymentStatus = `-- name: SetDeploymentStatus :exec
|
|
UPDATE deployments SET status = $1, updated_at = $2 WHERE id = $3
|
|
`
|
|
|
|
type SetDeploymentStatusParams struct {
|
|
Status sql.NullString `json:"status"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetDeploymentStatus(ctx context.Context, arg SetDeploymentStatusParams) error {
|
|
_, err := q.db.ExecContext(ctx, setDeploymentStatus, arg.Status, arg.UpdatedAt, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const setServiceStatus = `-- name: SetServiceStatus :exec
|
|
UPDATE services SET status = $1, updated_at = $2 WHERE id = $3
|
|
`
|
|
|
|
type SetServiceStatusParams struct {
|
|
Status sql.NullString `json:"status"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetServiceStatus(ctx context.Context, arg SetServiceStatusParams) error {
|
|
_, err := q.db.ExecContext(ctx, setServiceStatus, arg.Status, arg.UpdatedAt, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const syncDeploymentProgress = `-- name: SyncDeploymentProgress :exec
|
|
UPDATE deployments
|
|
SET status = $1,
|
|
image_name = $2,
|
|
image_tag = $3,
|
|
build_log = $4,
|
|
runtime_log = $5,
|
|
error = $6,
|
|
started_at = $7,
|
|
completed_at = $8,
|
|
updated_at = $9
|
|
WHERE id = $10
|
|
`
|
|
|
|
type SyncDeploymentProgressParams struct {
|
|
Status sql.NullString `json:"status"`
|
|
ImageName sql.NullString `json:"image_name"`
|
|
ImageTag sql.NullString `json:"image_tag"`
|
|
BuildLog sql.NullString `json:"build_log"`
|
|
RuntimeLog sql.NullString `json:"runtime_log"`
|
|
Error sql.NullString `json:"error"`
|
|
StartedAt sql.NullTime `json:"started_at"`
|
|
CompletedAt sql.NullTime `json:"completed_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SyncDeploymentProgress(ctx context.Context, arg SyncDeploymentProgressParams) error {
|
|
_, err := q.db.ExecContext(ctx, syncDeploymentProgress,
|
|
arg.Status,
|
|
arg.ImageName,
|
|
arg.ImageTag,
|
|
arg.BuildLog,
|
|
arg.RuntimeLog,
|
|
arg.Error,
|
|
arg.StartedAt,
|
|
arg.CompletedAt,
|
|
arg.UpdatedAt,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|