- Declarative source of truth:
supabase/schemas/**— the desired-state DDL (not currently populated — declarative export deferred per the 2026-06-09 pg-delta scaling spike; the generated docs below describe the live schema). - Entity relationships: the per-core ERDs (
FA_ERD,HR_ERD, …). - Authoring & promotion workflow:
DECLARATIVE_SCHEMA_GUIDE.mdandSUPABASE_CLI_LOCAL_WORKFLOW.md. - Generated per-core reference + ERDs:
docs/database/erd/— regenerated bynpm run db:docs:generatefrom the catalog snapshot. - AI-agent context:
docs/database/schema-llms.txt(+schema-index.json). - RLS / compliance posture:
docs/database/RLS_POSTURE.md.
Purpose
- Define schema ownership and guardrails at architecture level.
- Point to the declarative schema source of truth and ERDs.
- Avoid stale hand-maintained table inventories in architecture docs.
Source of Truth
- Canonical declarative DDL:
supabase/schemas/**/*.sql(desired final state; not currently populated — declarative export is deferred per the 2026-06-09 pg-delta scaling spike; migrations are the operative source of truth until a scalable backfill lands). - Promotion vehicle:
supabase/migrations/*.sql— the baseline (00000000000000_baseline_2026_05_28_ddl.sql+…_data.sql) plus forward,db diff-generated migrations. Migrations are the only artifact applied to hosted environments. - Runtime schema: Supabase Postgres — live projects are dev2 (
anuwknikgsijbameytzr) and prod2 (aximlomrwfuhctxjhrsf). - Generated TypeScript types:
src/integrations/supabase/types.ts, regenerated vianpm run db:types(local) /npm run db:types:dev2; CI runsnpm run db:types:check.
Promotion strategy
EncoreOS uses a declarative-first strategy: author DDL insupabase/schemas/**, generate migrations with supabase db diff, review, and apply via supabase db push. supabase/schemas/ is the canonical desired-state; migrations remain the reviewed, CI-gated promotion vehicle.
Core Schema Boundaries
Table naming follows{core}_{entity} where core prefixes are:
pf,ce,rh,fa,hr,gr,fw,fm,lo,it,cl,pm
- Cores depend on Platform Foundation patterns, not direct core-to-core coupling.
- Tenant isolation must be enforced by schema design plus RLS policy design.
- Cross-core links must follow constitution architecture boundaries.
Security and Tenant Isolation
All schema work must preserve constitution requirements:- Tenant scoping (
organization_id, andsite_idwhere applicable). - RLS on business tables in exposed schemas.
- UPDATE policies include both
USINGandWITH CHECK. - SECURITY DEFINER helpers use safe
search_pathand prevent recursive RLS patterns.
npm run db:check:rls-initplannpm run db:check:fk-indexesnpm run db:schemas:lint
Documentation Maintenance
The schema is documented by the declarativesupabase/schemas/** tree and the per-core ERDs — not by hand-maintained inventory files. To change the schema:
- Edit
supabase/schemas/**/*.sql(desired state). - Generate a migration:
npm run db:schemas:diff -- -f <name>. - Apply locally (
supabase db reset) and regenerate types (npm run db:types). - Review the migration + type diff before promotion.
DECLARATIVE_SCHEMA_GUIDE.md for the full workflow.