- agent: 6 auto-collecting registries (parsers/checks/risk/scoring/tools/pipelines); 15 doc parsers, 12 check packs, 6 risk models, scoring dimensions + reconciler, ~15 Claude tools, 8 pipelines (financing/underwriting/dpp/compliance/grading/esg) + routes; 380 tests - infra: BaseRepository + ~35 typed repositories, 56 composed schema modules, storage/queue/notifications/cache/events adapters; 203 tests - pnpm -r typecheck/build/test all green Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
3.0 KiB
Schema composition convention
The root schema.sql is a generated artifact. Do not edit it by hand.
It is the concatenation of the per-domain SQL modules in this directory, produced
by scripts/compose-schema.mjs (pnpm run schema:build).
Why
schema.sql is the single file the deploy path applies
(psql "$SUPABASE_DB_URL" -f schema.sql, or pasted into the Supabase SQL editor)
and it is exported from the package as @proofchain/infra/schema.sql. Splitting
it into modules lets Fill agents add one domain at a time without ever editing a
shared file or risking a merge conflict — you add a module, run the composer,
and the artifact is regenerated deterministically.
Fill convention (add a domain)
- Create a new file
schema/<NN>_<domain>.sqlwhere<NN>is a two-digit ordering key (see the ranges below). One domain per file. - Write idempotent DDL only:
- Tables:
create table if not exists …. - Functions:
create or replace function …. - Enums / triggers / policies: guard with
do $$ … end $$;blocks that checkpg_type/ usedrop … if existsbeforecreate. - This guarantees the composed
schema.sqlis safe to re-run on every deploy.
- Tables:
- Follow the existing column conventions (mirrored by the zod schemas in
src/types.tsand the repositories insrc/repositories/):- On-chain identifiers: lowercase hex
textwith acheck (col ~ '^0x[0-9a-f]{64}$')(32-byte) or'^0x[0-9a-f]{40}$'(address) constraint. uint256amounts:numeric(78, 0)withcheck (col >= 0).- Basis-point scores:
integer check (col between 0 and 10000). - Timestamps:
created_at/updated_at timestamptz not null default now(). - Attach the shared
set_updated_at()trigger to any table withupdated_at. - Enable RLS (
alter table … enable row level security) with a public read-onlyselectpolicy; all writes go through the service role.
- On-chain identifiers: lowercase hex
- Run
pnpm run schema:buildto regenerateschema.sql. CI can assert freshness withpnpm run schema:build -- --check.
Ordering ranges
| Key range | Purpose |
|---|---|
00 |
Core + SPEC2 tables (00_core.sql) — do not split. |
10–19 |
Trade finance |
20–29 |
Compliance |
30–39 |
Digital Product Passport (DPP) |
40–49 |
Logistics |
50–59 |
Commodities / energy / ESG |
60–69 |
Workforce |
70–79 |
Data / oracle |
90–99 |
Infra internals (queue, outbox, migrations, …) |
00_core.sql is the verbatim original schema, so existing tables are always
emitted first and never dropped. Modules only ever add new objects.