From ea9518e712b86049b2e17a3c4a26021ebf80fe89 Mon Sep 17 00:00:00 2001 From: Mathias Date: Mon, 25 May 2026 07:17:39 +0200 Subject: [PATCH] feat(graphstore): M1 add tier + topic columns to brain_entities (infra#72) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Schema-only change. DDL adds tier + topic on fresh tables and uses ADD COLUMN IF NOT EXISTS on existing tables (idempotent across pod restarts). New conditional indexes match the wing/hall pattern. No behavior change in this commit — UpsertEntity still writes only the original columns; tier + topic stay '' on every row. M2 plumbs the parser through. The empty default means existing queries are untouched until the rest of the chain lands. Part of infra#72 — brain DIKW tier redesign. --- ingestion/internal/graphstore/pg.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ingestion/internal/graphstore/pg.go b/ingestion/internal/graphstore/pg.go index 9061cfe..fa0942b 100644 --- a/ingestion/internal/graphstore/pg.go +++ b/ingestion/internal/graphstore/pg.go @@ -69,12 +69,24 @@ CREATE TABLE IF NOT EXISTS brain_entities ( hall TEXT NOT NULL DEFAULT '', doc_path TEXT NOT NULL, title TEXT NOT NULL DEFAULT '', + tier TEXT NOT NULL DEFAULT '', + topic TEXT NOT NULL DEFAULT '', updated_at TIMESTAMPTZ NOT NULL DEFAULT now() ); +-- Idempotent migration for clusters created before the DIKW tier +-- redesign (infra#72). ADD COLUMN IF NOT EXISTS is safe across +-- repeated startups. +ALTER TABLE brain_entities + ADD COLUMN IF NOT EXISTS tier TEXT NOT NULL DEFAULT '', + ADD COLUMN IF NOT EXISTS topic TEXT NOT NULL DEFAULT ''; CREATE INDEX IF NOT EXISTS brain_entities_wing_idx ON brain_entities (wing) WHERE wing <> ''; CREATE INDEX IF NOT EXISTS brain_entities_type_idx ON brain_entities (type); +CREATE INDEX IF NOT EXISTS brain_entities_tier_idx + ON brain_entities (tier) WHERE tier <> ''; +CREATE INDEX IF NOT EXISTS brain_entities_topic_idx + ON brain_entities (topic) WHERE topic <> ''; CREATE TABLE IF NOT EXISTS brain_edges ( id BIGSERIAL PRIMARY KEY,