CREATE TABLE nodes ( id TEXT PRIMARY KEY, type TEXT DEFAULT 'event', name TEXT DEFAULT '', year INTEGER, month TEXT DEFAULT '', month_num INTEGER DEFAULT 0, day INTEGER DEFAULT 0, time TEXT DEFAULT '', country TEXT DEFAULT '', region TEXT DEFAULT '', city TEXT DEFAULT '', slug TEXT DEFAULT '', layer INTEGER DEFAULT 0, visibility TEXT DEFAULT 'private', created_by TEXT DEFAULT 'system', tags TEXT[] DEFAULT '{}', one_liner TEXT DEFAULT '', figures TEXT[] DEFAULT '{}', flash_timepoint_id TEXT, flash_slug TEXT DEFAULT '', flash_share_url TEXT DEFAULT '', era TEXT DEFAULT '', created_at TIMESTAMPTZ DEFAULT now(), published_at TIMESTAMPTZ, source_type TEXT DEFAULT 'historical', confidence FLOAT, source_run_id TEXT, tdf_hash TEXT NOT NULL);
edges table
Stores relationships between nodes:
CREATE TABLE edges ( source TEXT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, target TEXT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE, type TEXT NOT NULL CHECK (type IN ('causes','contemporaneous','same_location','thematic')), weight FLOAT DEFAULT 1.0, theme TEXT DEFAULT '', PRIMARY KEY (source, target, type));
CREATE INDEX idx_nodes_visibility ON nodes(visibility);CREATE INDEX idx_nodes_month_day ON nodes(month, day);CREATE INDEX idx_nodes_year ON nodes(year);CREATE INDEX idx_nodes_location ON nodes(country, region, city);CREATE INDEX idx_nodes_tags ON nodes USING GIN(tags);CREATE INDEX idx_nodes_figures ON nodes USING GIN(figures);CREATE INDEX idx_edges_source ON edges(source);CREATE INDEX idx_edges_target ON edges(target);CREATE INDEX idx_nodes_source_type ON nodes(source_type);
If pg_trgm extension is available, trigram indexes are created automatically:
CREATE EXTENSION IF NOT EXISTS pg_trgm;CREATE INDEX idx_nodes_name_trgm ON nodes USING GIN(name gin_trgm_ops);CREATE INDEX idx_nodes_one_liner_trgm ON nodes USING GIN(one_liner gin_trgm_ops);
# Local PostgreSQLexport DATABASE_URL="postgresql://localhost:5432/clockchain"# With credentialsexport DATABASE_URL="postgresql://user:password@localhost:5432/clockchain"# Docker containerexport DATABASE_URL="postgresql://postgres:test@localhost:5432/clockchain"