Files
Docker-Manager/backend/migrations/000001_init.up.sql
T
Admin 570c4acdaa Strip comments from backend and frontend source
Remove Go doc comments, TS/Svelte scaffold comments and explanatory
notes left over from the initial scaffold, plus a few leftover Spanish
notes in the compose file, SQL scripts and env template. Also drops
frontend/src/lib/index.ts, which only held the SvelteKit placeholder
comment and was never imported.
2026-09-21 19:45:42 +02:00

41 lines
1.6 KiB
SQL

CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE hosts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL UNIQUE,
connection_type TEXT NOT NULL DEFAULT 'local' CHECK (connection_type IN ('local', 'agent', 'tcp')),
endpoint_url TEXT,
agent_token_hash TEXT,
status TEXT NOT NULL DEFAULT 'unknown' CHECK (status IN ('unknown', 'online', 'offline')),
last_seen_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE services (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
display_name TEXT NOT NULL,
container_name_or_id TEXT NOT NULL,
compose_project TEXT,
tags TEXT[] NOT NULL DEFAULT '{}',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE (host_id, container_name_or_id)
);
CREATE TABLE audit_log (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_sub TEXT NOT NULL,
action TEXT NOT NULL,
target_type TEXT NOT NULL,
target_id TEXT NOT NULL,
host_id UUID REFERENCES hosts(id) ON DELETE SET NULL,
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_services_host_id ON services(host_id);
CREATE INDEX idx_audit_log_created_at ON audit_log(created_at DESC);
CREATE INDEX idx_audit_log_user_sub ON audit_log(user_sub);
INSERT INTO hosts (name, connection_type) VALUES ('local', 'local');