Files
ai-taxonomy-literature-anal…/db/analysis-schema.sql
T

49 lines
2.4 KiB
SQL

-- Analysis articles: one article per (paper, topic); each article has its own ordered, nestable sections;
-- each section is an ordered list of typed blocks. Lives in its own schema so the data rebuild
-- (which replaces schema "live" on every deploy) never touches it.
CREATE SCHEMA IF NOT EXISTS analysis;
CREATE TABLE IF NOT EXISTS analysis.article (
id bigserial PRIMARY KEY,
slug text NOT NULL UNIQUE,
subject_conf text NOT NULL, -- the paper this is about, by its stable key (conf, ext_id):
subject_ext_id text NOT NULL, -- papers.id is not stable across data rebuilds
title text NOT NULL,
summary text,
revision integer NOT NULL DEFAULT 1,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_article_subject ON analysis.article (subject_conf, subject_ext_id);
CREATE TABLE IF NOT EXISTS analysis.section (
id bigserial PRIMARY KEY,
article_id bigint NOT NULL REFERENCES analysis.article(id) ON DELETE CASCADE,
parent_id bigint REFERENCES analysis.section(id) ON DELETE CASCADE, -- nesting
key text NOT NULL, -- anchor / stable name, e.g. 'key-contribution'
title text NOT NULL,
level integer NOT NULL DEFAULT 2, -- heading level (2 or 3)
position integer NOT NULL, -- order among siblings
UNIQUE (article_id, key)
);
CREATE TABLE IF NOT EXISTS analysis.block (
id bigserial PRIMARY KEY,
section_id bigint NOT NULL REFERENCES analysis.section(id) ON DELETE CASCADE,
position integer NOT NULL,
type text NOT NULL CHECK (type IN ('markdown','list','callout','table','chart','mermaid','figure','code')),
data jsonb NOT NULL, -- shape depends on type (see scripts/load-articles.js)
UNIQUE (section_id, position)
);
CREATE TABLE IF NOT EXISTS analysis.link (
id bigserial PRIMARY KEY,
article_id bigint NOT NULL REFERENCES analysis.article(id) ON DELETE CASCADE,
section_id bigint REFERENCES analysis.section(id) ON DELETE SET NULL,
position integer NOT NULL,
kind text NOT NULL CHECK (kind IN ('paper','code','project','demo','dataset','related','other')),
title text NOT NULL,
url text NOT NULL,
note text
);