Initial scaffold: backend base + docker-compose dev infra + sveltekit frontend
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
DROP TABLE IF EXISTS audit_log;
|
||||
DROP TABLE IF EXISTS services;
|
||||
DROP TABLE IF EXISTS hosts;
|
||||
@@ -0,0 +1,41 @@
|
||||
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);
|
||||
|
||||
-- Host único de la Fase 1: el mismo servidor donde corre el backend.
|
||||
INSERT INTO hosts (name, connection_type) VALUES ('local', 'local');
|
||||
Reference in New Issue
Block a user