Consolidate backend: drop vendored APwhy, converge on goose + sqlc

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]>
This commit is contained in:
Tomas Dvorak committed 2026-09-17 09:40:08 +02:00
1 parent 37a56dc6b6
commit 9e3aa3aa17
153 files changed
+6996 -11135

No files matched your search

+109
View File
@@ -0,0 +1,109 @@
-- name: GetAgentByHostAndIP :one
SELECT * FROM node_agents
WHERE hostname = $1 AND ip_address = $2
LIMIT 1;
-- name: GetAgent :one
SELECT * FROM node_agents WHERE id = $1;
-- name: ListAgents :many
SELECT * FROM node_agents ORDER BY created_at ASC;
-- name: CreateAgent :one
INSERT INTO node_agents (
id, name, hostname, ip_address, port, status, version,
capabilities, resources, last_heartbeat, metadata
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
RETURNING *;
-- name: UpdateAgent :one
UPDATE node_agents SET
name = $2,
hostname = $3,
ip_address = $4,
port = $5,
status = $6,
version = $7,
capabilities = $8,
resources = $9,
last_heartbeat = $10,
metadata = $11,
updated_at = NOW()
WHERE id = $1
RETURNING *;
-- name: UpdateAgentHeartbeat :exec
UPDATE node_agents SET
status = $2,
resources = $3,
last_heartbeat = $4,
updated_at = NOW()
WHERE id = $1;
-- name: DeleteAgent :exec
DELETE FROM node_agents WHERE id = $1;
-- name: InsertAgentHeartbeat :exec
INSERT INTO agent_heartbeats (
id, node_agent_id, timestamp, status, resources,
container_count, system_load, uptime, version
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
-- name: ListAgentHeartbeatsSince :many
SELECT * FROM agent_heartbeats
WHERE node_agent_id = $1 AND timestamp >= $2
ORDER BY timestamp ASC;
-- name: ListPendingCommands :many
SELECT * FROM agent_commands
WHERE node_agent_id = $1 AND status = 'pending'
ORDER BY created_at ASC
LIMIT 25;
-- name: ListCommandsForAgent :many
SELECT * FROM agent_commands
WHERE node_agent_id = $1
ORDER BY created_at DESC;
-- name: GetCommandForAgent :one
SELECT * FROM agent_commands
WHERE id = $1 AND node_agent_id = $2;
-- name: CreateCommand :one
INSERT INTO agent_commands (
id, type, node_agent_id, container_id, payload, status
) VALUES ($1, $2, $3, $4, $5, 'pending')
RETURNING *;
-- name: CompleteCommand :one
UPDATE agent_commands SET
status = $3,
result = $4,
error = $5,
completed_at = NOW(),
updated_at = NOW()
WHERE id = $1 AND node_agent_id = $2
RETURNING *;
-- name: ListContainersForAgent :many
SELECT * FROM container_instances
WHERE node_agent_id = $1;
-- name: GetContainerForAgent :one
SELECT * FROM container_instances
WHERE id = $1 AND node_agent_id = $2;
-- name: GetContainer :one
SELECT * FROM container_instances WHERE id = $1;
-- name: CreateContainer :one
INSERT INTO container_instances (
id, name, image, project_id, service_id, node_agent_id,
status, resources, ports, environment, volumes, networks,
restart_policy, health_check
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
RETURNING *;
-- name: UpdateContainerStatus :exec
UPDATE container_instances SET status = $2, updated_at = NOW()
WHERE id = $1;
+87 -10
View File
@@ -25,19 +25,33 @@ CREATE TABLE environments (
);
CREATE TABLE services (
id UUID PRIMARY KEY,
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL,
type VARCHAR(50) NOT NULL,
status VARCHAR(50) NOT NULL,
image TEXT,
command TEXT,
environment VARCHAR(50) DEFAULT 'production',
cpu VARCHAR(20) DEFAULT '0.5',
memory VARCHAR(20) DEFAULT '512Mi',
description TEXT,
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
environment_id UUID NOT NULL REFERENCES environments(id) ON DELETE CASCADE,
service_type VARCHAR(50) NOT NULL,
source_type VARCHAR(50) NOT NULL,
source_url VARCHAR(500),
image_name VARCHAR(500),
build_command TEXT,
start_command TEXT,
cpu_limit INTEGER,
memory_limit INTEGER,
public_url VARCHAR(500),
health_check_url VARCHAR(500),
status VARCHAR(50) DEFAULT 'created',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(project_id, name)
type VARCHAR(50),
image VARCHAR(500),
command TEXT,
environment VARCHAR(50),
git_repo VARCHAR(500),
git_branch VARCHAR(100),
build_path VARCHAR(500),
cpu VARCHAR(50),
memory VARCHAR(50)
);
CREATE TABLE deployments (
@@ -95,3 +109,66 @@ CREATE TABLE database_backups (
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
completed_at TIMESTAMP WITH TIME ZONE
);
CREATE TABLE node_agents (
id VARCHAR(255) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
hostname VARCHAR(255) NOT NULL,
ip_address VARCHAR(45) NOT NULL,
port INTEGER NOT NULL,
status VARCHAR(50) DEFAULT 'offline',
version VARCHAR(50),
capabilities JSONB,
resources JSONB,
last_heartbeat TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
metadata JSONB
);
CREATE TABLE container_instances (
id VARCHAR(255) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
image VARCHAR(255) NOT NULL,
project_id VARCHAR(255) NOT NULL,
service_id VARCHAR(255) NOT NULL,
node_agent_id VARCHAR(255) NOT NULL REFERENCES node_agents(id) ON DELETE CASCADE,
status JSONB,
resources JSONB,
ports JSONB,
environment JSONB,
volumes JSONB,
networks JSONB,
restart_policy JSONB,
health_check JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
started_at TIMESTAMP WITH TIME ZONE,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE agent_commands (
id VARCHAR(255) PRIMARY KEY,
type VARCHAR(100) NOT NULL,
node_agent_id VARCHAR(255) NOT NULL REFERENCES node_agents(id) ON DELETE CASCADE,
container_id VARCHAR(255) REFERENCES container_instances(id) ON DELETE CASCADE,
payload JSONB,
status VARCHAR(50) DEFAULT 'pending',
result TEXT,
error TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
completed_at TIMESTAMP WITH TIME ZONE
);
CREATE TABLE agent_heartbeats (
id VARCHAR(255) PRIMARY KEY,
node_agent_id VARCHAR(255) NOT NULL REFERENCES node_agents(id) ON DELETE CASCADE,
timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(),
status VARCHAR(50) NOT NULL DEFAULT 'unknown',
resources JSONB NOT NULL DEFAULT '{}'::jsonb,
container_count INTEGER NOT NULL DEFAULT 0,
system_load JSONB NOT NULL DEFAULT '{}'::jsonb,
uptime BIGINT NOT NULL DEFAULT 0,
version VARCHAR(50) NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);