⚒️ PostgreSQL Schema Design — Federation Data Layer
DITEMPA BUKAN DIBERI — Forged, Not Given.
Purpose
Design and maintain PostgreSQL schemas for the federation: capability registry, organ pulse history, drift detection, witness receipts, session state, cooling ledger entries.
When to Use
- Designing new tables or migrations for arifOS, AAA, GEOX, WEALTH, WELL Postgres backends
- Schema for capability registry (tool manifest storage)
- Pulse history tables (organ health time series)
- Drift detection storage (source ↔ runtime comparison snapshots)
- Witness receipt tables (tri-witness evidence logs)
When NOT to Use
- Vector/semantic search — use
redis-qdrant-integration
- Immutable append-only ledger — use
vault999-witness
- Caching layer — use
redis-qdrant-integration
- Frontend state — use
react-spa-discipline
Constitutional Floor Alignment
| Floor |
Application |
| F1 AMANAH |
All schema changes via migration files; never ALTER TABLE in production |
| F2 TRUTH |
Columns typed precisely (TIMESTAMPTZ, UUID, JSONB) — no varchar(255) laziness |
| F4 CLARITY |
Normalize to 3NF by default; only denormalize for measured query perf |
| F11 AUDIT |
Every table has created_at, updated_at, actor_id audit columns |
| F13 SOVEREIGN |
Schema drops require 888_HOLD — data is civilizational memory |
Commands & Patterns
-- Capability registry table pattern
CREATE TABLE capability_registry (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
organ_id TEXT NOT NULL REFERENCES organs(id),
tool_name TEXT NOT NULL,
schema_json JSONB NOT NULL,
status TEXT NOT NULL DEFAULT 'active',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
actor_id TEXT NOT NULL
);
-- Pulse history (time-series)
CREATE TABLE organ_pulses (
id BIGSERIAL PRIMARY KEY,
organ_id TEXT NOT NULL,
status TEXT NOT NULL,
latency_ms INTEGER,
payload JSONB,
sampled_at TIMESTAMPTZ NOT NULL DEFAULT now()
) PARTITION BY RANGE (sampled_at);
-- Migration pattern — always reversible
-- V001__create_capability_registry.sql
-- V002__add_organ_pulses.sql
Refusal Surface
- ❌
SELECT * in production queries — always name columns
- ❌ Schema changes without migration files
- ❌ Storing JSON when relational columns fit the data
- ❌ Missing indexes on foreign keys and
sampled_at columns
- ❌
DROP COLUMN or DROP TABLE without 888_HOLD
1---2name: forge-postgres-schema-design3description: PostgreSQL schema design for the federation data layer — migrations, indexing, and entity modeling.4---5# ⚒️ PostgreSQL Schema Design — Federation Data Layer67> **DITEMPA BUKAN DIBERI** — Forged, Not Given.89## Purpose10Design and maintain PostgreSQL schemas for the federation: capability registry, organ pulse history, drift detection, witness receipts, session state, cooling ledger entries.1112## When to Use13- Designing new tables or migrations for arifOS, AAA, GEOX, WEALTH, WELL Postgres backends14- Schema for capability registry (tool manifest storage)15- Pulse history tables (organ health time series)16- Drift detection storage (source ↔ runtime comparison snapshots)17- Witness receipt tables (tri-witness evidence logs)1819## When NOT to Use20- Vector/semantic search — use `redis-qdrant-integration`21- Immutable append-only ledger — use `vault999-witness`22- Caching layer — use `redis-qdrant-integration`23- Frontend state — use `react-spa-discipline`2425## Constitutional Floor Alignment2627| Floor | Application |28|-------|-------------|29| F1 AMANAH | All schema changes via migration files; never `ALTER TABLE` in production |30| F2 TRUTH | Columns typed precisely (TIMESTAMPTZ, UUID, JSONB) — no varchar(255) laziness |31| F4 CLARITY | Normalize to 3NF by default; only denormalize for measured query perf |32| F11 AUDIT | Every table has `created_at`, `updated_at`, `actor_id` audit columns |33| F13 SOVEREIGN | Schema drops require 888_HOLD — data is civilizational memory |3435## Commands & Patterns3637```sql38-- Capability registry table pattern39CREATE TABLE capability_registry (40 id UUID PRIMARY KEY DEFAULT gen_random_uuid(),41 organ_id TEXT NOT NULL REFERENCES organs(id),42 tool_name TEXT NOT NULL,43 schema_json JSONB NOT NULL,44 status TEXT NOT NULL DEFAULT 'active',45 created_at TIMESTAMPTZ NOT NULL DEFAULT now(),46 updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),47 actor_id TEXT NOT NULL48);4950-- Pulse history (time-series)51CREATE TABLE organ_pulses (52 id BIGSERIAL PRIMARY KEY,53 organ_id TEXT NOT NULL,54 status TEXT NOT NULL,55 latency_ms INTEGER,56 payload JSONB,57 sampled_at TIMESTAMPTZ NOT NULL DEFAULT now()58) PARTITION BY RANGE (sampled_at);5960-- Migration pattern — always reversible61-- V001__create_capability_registry.sql62-- V002__add_organ_pulses.sql63```6465## Refusal Surface66- ❌ `SELECT *` in production queries — always name columns67- ❌ Schema changes without migration files68- ❌ Storing JSON when relational columns fit the data69- ❌ Missing indexes on foreign keys and `sampled_at` columns70- ❌ `DROP COLUMN` or `DROP TABLE` without 888_HOLD