feat: add report center

This commit is contained in:
2026-06-24 17:26:04 +08:00
parent f0ac47e040
commit 049d6a711e
7 changed files with 841 additions and 21 deletions

View File

@@ -0,0 +1,28 @@
CREATE TABLE IF NOT EXISTS app.reports (
report_id BIGSERIAL PRIMARY KEY,
report_type TEXT NOT NULL CHECK (report_type IN ('monthly', 'area_special', 'neighborhood_memo')),
title TEXT NOT NULL,
target_month TEXT CHECK (target_month IS NULL OR target_month ~ '^[0-9]{4}-[0-9]{2}$'),
area_id TEXT REFERENCES silver.areas(area_id),
neighborhood_id TEXT REFERENCES silver.neighborhoods(neighborhood_id),
summary TEXT NOT NULL DEFAULT '',
content_markdown TEXT NOT NULL,
linked_metrics JSONB NOT NULL DEFAULT '{}'::jsonb,
status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'published', 'archived')),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CHECK (char_length(title) > 0),
CHECK (char_length(content_markdown) > 0)
);
CREATE INDEX IF NOT EXISTS idx_reports_type_month
ON app.reports(report_type, target_month, report_id DESC);
CREATE INDEX IF NOT EXISTS idx_reports_area
ON app.reports(area_id, report_id DESC);
CREATE INDEX IF NOT EXISTS idx_reports_neighborhood
ON app.reports(neighborhood_id, report_id DESC);
CREATE INDEX IF NOT EXISTS idx_reports_linked_metrics
ON app.reports USING GIN (linked_metrics);