chore: full stack stability and migration fixes, plus react UI progress
Some checks failed
CI / podman-build (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-03-18 09:01:38 +02:00
parent 38cab8c246
commit a66d908eff
142 changed files with 12210 additions and 3402 deletions

View File

@@ -0,0 +1,30 @@
-- This migration runs on the CONTROL PLANE database (port 5433), not the tenant DB.
-- We need to ensure we migrate the correct DB.
-- For MVP, if we only have one migration pipeline, we might mix them?
-- Ideally we use `sqlx migrate run --database-url ...` for this specific migration.
-- Or we just put this table in the main DB for the MVP to avoid infrastructure complexity?
-- The `docker-compose.yml` has `control_db`.
-- Let's try to use the main DB for everything in MVP to reduce friction,
-- OR use a separate folder for control plane migrations.
-- Let's put `projects` in the `public` schema of the main DB for simplicity of the "Single Tenant / Self Hosted" mode.
-- In a real SaaS, this would be separate.
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE IF NOT EXISTS projects (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
name TEXT NOT NULL,
owner_id UUID, -- No FK to users strictly required if users are in tenant DB, but here they are same DB.
status TEXT DEFAULT 'active',
db_url TEXT NOT NULL,
jwt_secret TEXT NOT NULL DEFAULT encode(gen_random_bytes(32), 'hex'),
anon_key TEXT,
service_role_key TEXT,
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
-- Trigger to generate keys on insert? Or handle in code.
-- Let's handle in code for keys.

View File

@@ -0,0 +1,95 @@
-- Server management tables
-- Merged from control-plane-api/migrations/001_initial.sql
-- Servers table
CREATE TABLE IF NOT EXISTS servers (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL UNIQUE,
template VARCHAR(100) NOT NULL,
pillar VARCHAR(50) NOT NULL DEFAULT 'worker',
provider VARCHAR(50) NOT NULL DEFAULT 'generic',
vps_server_id VARCHAR(100) NOT NULL,
ip_address VARCHAR(50) NOT NULL,
status VARCHAR(50) NOT NULL DEFAULT 'provisioning',
environment VARCHAR(50) DEFAULT 'production',
region VARCHAR(50) NOT NULL DEFAULT 'local',
plan VARCHAR(50) NOT NULL DEFAULT 'custom',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
last_heartbeat TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Scaling operations tracking table
CREATE TABLE IF NOT EXISTS scaling_operations (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
operation_type VARCHAR(50) NOT NULL,
status VARCHAR(50) NOT NULL DEFAULT 'pending',
total_steps INTEGER NOT NULL,
completed_steps INTEGER DEFAULT 0,
details JSONB,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Backups table
CREATE TABLE IF NOT EXISTS backups (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
url VARCHAR(500) NOT NULL,
size_bytes BIGINT DEFAULT 0,
status VARCHAR(50) DEFAULT 'completed',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
expires_at TIMESTAMP WITH TIME ZONE
);
-- Server metrics table
CREATE TABLE IF NOT EXISTS server_metrics (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
server_id UUID REFERENCES servers(id) ON DELETE CASCADE,
cpu_usage DECIMAL(5,2),
memory_usage DECIMAL(5,2),
disk_usage DECIMAL(5,2),
connections_count INTEGER,
status VARCHAR(50),
recorded_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Cluster events table (audit log)
CREATE TABLE IF NOT EXISTS cluster_events (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
event_type VARCHAR(100) NOT NULL,
server_id UUID REFERENCES servers(id) ON DELETE SET NULL,
details JSONB,
initiated_by VARCHAR(255) DEFAULT 'system',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Indexes
CREATE INDEX IF NOT EXISTS idx_servers_status ON servers(status);
CREATE INDEX IF NOT EXISTS idx_servers_template ON servers(template);
CREATE INDEX IF NOT EXISTS idx_servers_provider ON servers(provider);
CREATE INDEX IF NOT EXISTS idx_servers_pillar ON servers(pillar);
CREATE INDEX IF NOT EXISTS idx_servers_created_at ON servers(created_at);
CREATE INDEX IF NOT EXISTS idx_backups_created_at ON backups(created_at);
CREATE INDEX IF NOT EXISTS idx_server_metrics_server_id ON server_metrics(server_id);
CREATE INDEX IF NOT EXISTS idx_server_metrics_recorded_at ON server_metrics(recorded_at);
CREATE INDEX IF NOT EXISTS idx_cluster_events_server_id ON cluster_events(server_id);
CREATE INDEX IF NOT EXISTS idx_cluster_events_created_at ON cluster_events(created_at);
CREATE INDEX IF NOT EXISTS idx_scaling_operations_status ON scaling_operations(status);
-- Trigger to update updated_at timestamp
CREATE OR REPLACE FUNCTION update_servers_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ language 'plpgsql';
DROP TRIGGER IF EXISTS update_servers_updated_at ON servers;
CREATE TRIGGER update_servers_updated_at BEFORE UPDATE ON servers
FOR EACH ROW EXECUTE FUNCTION update_servers_updated_at_column();
-- Insert default control plane server entry
INSERT INTO servers (name, template, pillar, provider, vps_server_id, ip_address, status, region, plan)
VALUES ('control-plane-1', 'control-plane-node', 'system', 'generic', 'local', '127.0.0.1', 'active', 'local', 'custom')
ON CONFLICT (name) DO NOTHING;