From c8edc8e5dacac758e2eca2de20657c3e15a6f942 Mon Sep 17 00:00:00 2001 From: a2a-cloud Date: Sun, 19 Jul 2026 19:51:33 +0000 Subject: [PATCH] a2a-source-edit: write db/migrations/001_app_records.sql --- db/migrations/001_app_records.sql | 51 ++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/db/migrations/001_app_records.sql b/db/migrations/001_app_records.sql index 9317315..53ce89b 100644 --- a/db/migrations/001_app_records.sql +++ b/db/migrations/001_app_records.sql @@ -1,11 +1,46 @@ -CREATE TABLE IF NOT EXISTS app_records ( - id BIGSERIAL PRIMARY KEY, +CREATE TABLE IF NOT EXISTS dashboard_runs ( + id UUID PRIMARY KEY, tenant_key TEXT NOT NULL, - record_kind TEXT NOT NULL, - payload JSONB NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), - updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() + agency_name TEXT NOT NULL, + window_label TEXT NOT NULL, + min_severity TEXT NOT NULL DEFAULT 'all', + input_hash TEXT NOT NULL, + summary TEXT NOT NULL, + filters JSONB NOT NULL DEFAULT '{}'::jsonb, + trends JSONB NOT NULL DEFAULT '{}'::jsonb, + exceptions JSONB NOT NULL DEFAULT '[]'::jsonb, + dashboard_rows JSONB NOT NULL DEFAULT '[]'::jsonb, + artifact_name TEXT NOT NULL, + artifact_media_type TEXT NOT NULL, + artifact_size_bytes INTEGER NOT NULL DEFAULT 0, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); -CREATE INDEX IF NOT EXISTS app_records_tenant_kind_idx - ON app_records (tenant_key, record_kind, created_at DESC); +CREATE INDEX IF NOT EXISTS dashboard_runs_tenant_created_idx + ON dashboard_runs (tenant_key, created_at DESC); + +CREATE INDEX IF NOT EXISTS dashboard_runs_tenant_hash_idx + ON dashboard_runs (tenant_key, input_hash); + +CREATE TABLE IF NOT EXISTS execution_receipts ( + id UUID PRIMARY KEY, + tenant_key TEXT NOT NULL, + run_id UUID NOT NULL REFERENCES dashboard_runs(id) ON DELETE CASCADE, + skill_name TEXT NOT NULL, + status TEXT NOT NULL, + input_hash TEXT NOT NULL, + result_overview JSONB NOT NULL DEFAULT '{}'::jsonb, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE INDEX IF NOT EXISTS execution_receipts_tenant_created_idx + ON execution_receipts (tenant_key, created_at DESC); + +CREATE TABLE IF NOT EXISTS scheduled_rollups ( + tenant_key TEXT NOT NULL, + run_key TEXT NOT NULL, + run_id UUID NOT NULL REFERENCES dashboard_runs(id) ON DELETE CASCADE, + receipt_id UUID NOT NULL REFERENCES execution_receipts(id) ON DELETE CASCADE, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + PRIMARY KEY (tenant_key, run_key) +);