mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +00:00
Phase 0 cleanup verified end-to-end:
- Delete vendored APwhy runtime (cmd/apwhy, internal/apwhy) and the
unwired copy (internal/api/server.go + static bundle + cloned
internal/{storage,analytics,auth,rbac}) — ~7.5k lines of dead code.
- Keep Containr's native internal/gateway; move APwhy management
routes under /api/v1/gateway/* so they stop colliding with the
native /services paths. Fix handlers against the real schema:
UUID ids via RETURNING, integer enabled flags, plan validation,
service validate endpoint, unique-violation mapping.
- Port agents.go off GORM onto sqlc (sqlc/queries/agents.sql);
drop gorm dependencies; fix sqlc schema drift (services.environment_id).
- Replace the SELECT 1 goose baseline with the real consolidated
schema (52 tables) minus APwhy's parallel auth/RBAC objects;
idempotent via IF NOT EXISTS / OR REPLACE / guarded DO blocks so it
replays cleanly over legacy installs. Add a drop migration for the
dead objects and delete the legacy filename-tracked migrations/
loader, directory, and Dockerfile copy. Verified via cmd/migrate:
fresh install 53 tables, legacy upgrade clean to 20260917000000.
- Canvas: add invisible React Flow handles to ServiceNode so inferred
auto-connections stop emitting warning #008.
- Remove reactflow dep (superseded by @xyflow/react), test harness
cmds, and legacy 0001_init.sql backups.
Authored By: TDvorak <[email protected]>
274 lines
6.4 KiB
Go
274 lines
6.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: templates.sql
|
|
|
|
package sqlcdb
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const countServicesByProjectAndName = `-- name: CountServicesByProjectAndName :one
|
|
SELECT COUNT(*)
|
|
FROM services
|
|
WHERE project_id = $1 AND name = $2
|
|
`
|
|
|
|
type CountServicesByProjectAndNameParams struct {
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func (q *Queries) CountServicesByProjectAndName(ctx context.Context, arg CountServicesByProjectAndNameParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countServicesByProjectAndName, arg.ProjectID, arg.Name)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createServiceFromTemplate = `-- name: CreateServiceFromTemplate :exec
|
|
INSERT INTO services (
|
|
id,
|
|
project_id,
|
|
name,
|
|
environment_id,
|
|
service_type,
|
|
source_type,
|
|
source_url,
|
|
image_name,
|
|
build_command,
|
|
start_command,
|
|
type,
|
|
status,
|
|
image,
|
|
command,
|
|
environment,
|
|
cpu,
|
|
memory,
|
|
created_at,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12,
|
|
$13,
|
|
$14,
|
|
$15,
|
|
$16,
|
|
$17,
|
|
$18,
|
|
$19
|
|
)
|
|
`
|
|
|
|
type CreateServiceFromTemplateParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
Name string `json:"name"`
|
|
EnvironmentID uuid.UUID `json:"environment_id"`
|
|
ServiceType string `json:"service_type"`
|
|
SourceType string `json:"source_type"`
|
|
SourceUrl sql.NullString `json:"source_url"`
|
|
ImageName sql.NullString `json:"image_name"`
|
|
BuildCommand sql.NullString `json:"build_command"`
|
|
StartCommand sql.NullString `json:"start_command"`
|
|
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"`
|
|
Cpu sql.NullString `json:"cpu"`
|
|
Memory sql.NullString `json:"memory"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateServiceFromTemplate(ctx context.Context, arg CreateServiceFromTemplateParams) error {
|
|
_, err := q.db.ExecContext(ctx, createServiceFromTemplate,
|
|
arg.ID,
|
|
arg.ProjectID,
|
|
arg.Name,
|
|
arg.EnvironmentID,
|
|
arg.ServiceType,
|
|
arg.SourceType,
|
|
arg.SourceUrl,
|
|
arg.ImageName,
|
|
arg.BuildCommand,
|
|
arg.StartCommand,
|
|
arg.Type,
|
|
arg.Status,
|
|
arg.Image,
|
|
arg.Command,
|
|
arg.Environment,
|
|
arg.Cpu,
|
|
arg.Memory,
|
|
arg.CreatedAt,
|
|
arg.UpdatedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const getProjectOwnerID = `-- name: GetProjectOwnerID :one
|
|
SELECT owner_id
|
|
FROM projects
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetProjectOwnerID(ctx context.Context, id uuid.UUID) (uuid.UUID, error) {
|
|
row := q.db.QueryRowContext(ctx, getProjectOwnerID, id)
|
|
var owner_id uuid.UUID
|
|
err := row.Scan(&owner_id)
|
|
return owner_id, err
|
|
}
|
|
|
|
const getServiceTemplateByID = `-- name: GetServiceTemplateByID :one
|
|
SELECT id, name, description, category, logo, config, variables, is_official, created_at, updated_at
|
|
FROM service_templates
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetServiceTemplateByID(ctx context.Context, id string) (ServiceTemplate, error) {
|
|
row := q.db.QueryRowContext(ctx, getServiceTemplateByID, id)
|
|
var i ServiceTemplate
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Category,
|
|
&i.Logo,
|
|
&i.Config,
|
|
&i.Variables,
|
|
&i.IsOfficial,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listServiceTemplates = `-- name: ListServiceTemplates :many
|
|
SELECT id, name, description, category, logo, config, variables, is_official, created_at, updated_at
|
|
FROM service_templates
|
|
ORDER BY is_official DESC, name ASC
|
|
`
|
|
|
|
func (q *Queries) ListServiceTemplates(ctx context.Context) ([]ServiceTemplate, error) {
|
|
rows, err := q.db.QueryContext(ctx, listServiceTemplates)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ServiceTemplate{}
|
|
for rows.Next() {
|
|
var i ServiceTemplate
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Category,
|
|
&i.Logo,
|
|
&i.Config,
|
|
&i.Variables,
|
|
&i.IsOfficial,
|
|
&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 listServiceTemplatesByCategory = `-- name: ListServiceTemplatesByCategory :many
|
|
SELECT id, name, description, category, logo, config, variables, is_official, created_at, updated_at
|
|
FROM service_templates
|
|
WHERE category = $1
|
|
ORDER BY is_official DESC, name ASC
|
|
`
|
|
|
|
func (q *Queries) ListServiceTemplatesByCategory(ctx context.Context, category string) ([]ServiceTemplate, error) {
|
|
rows, err := q.db.QueryContext(ctx, listServiceTemplatesByCategory, category)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ServiceTemplate{}
|
|
for rows.Next() {
|
|
var i ServiceTemplate
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Category,
|
|
&i.Logo,
|
|
&i.Config,
|
|
&i.Variables,
|
|
&i.IsOfficial,
|
|
&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 upsertEnvironmentVariable = `-- name: UpsertEnvironmentVariable :exec
|
|
INSERT INTO environment_variables (id, service_id, key, value, is_secret, created_at, updated_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
ON CONFLICT (service_id, key) DO UPDATE
|
|
SET value = EXCLUDED.value,
|
|
is_secret = EXCLUDED.is_secret,
|
|
updated_at = EXCLUDED.updated_at
|
|
`
|
|
|
|
type UpsertEnvironmentVariableParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ServiceID uuid.UUID `json:"service_id"`
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
IsSecret sql.NullBool `json:"is_secret"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) UpsertEnvironmentVariable(ctx context.Context, arg UpsertEnvironmentVariableParams) error {
|
|
_, err := q.db.ExecContext(ctx, upsertEnvironmentVariable,
|
|
arg.ID,
|
|
arg.ServiceID,
|
|
arg.Key,
|
|
arg.Value,
|
|
arg.IsSecret,
|
|
arg.CreatedAt,
|
|
arg.UpdatedAt,
|
|
)
|
|
return err
|
|
}
|