readonly ["memo", "fact_ref", "fact"] import {FACT_DROP_TABLES} from '@fuzdev/fuz_app/db/fact_ddl.js'; Tables created by FACT_MIGRATION_NS, in drop order (children first).
Fact + memo PG schema.
Three tables:
fact — content-addressed bytes. hash = 'blake3:<hex64>'. Either
embedded (bytes) or referenced (external_url); the CHECK constraint
enforces exactly one populated. Idempotent: same bytes always produce
the same hash, so INSERT … ON CONFLICT DO NOTHING is the put primitive.fact_ref — declared dependency edges (source fact → target fact).
target_hash is intentionally not a foreign key: in federation a
reference may target a fact stored on another instance.memo — (fn_id, input_hash) → output_hash for memoized computations.8 declarations
readonly ["memo", "fact_ref", "fact"] import {FACT_DROP_TABLES} from '@fuzdev/fuz_app/db/fact_ddl.js'; Tables created by FACT_MIGRATION_NS, in drop order (children first).
"fuz_facts" import {FACT_MIGRATION_NAMESPACE} from '@fuzdev/fuz_app/db/fact_ddl.js'; Namespace identifier for fact + memo migrations.
MigrationNamespace import {FACT_MIGRATION_NS} from '@fuzdev/fuz_app/db/fact_ddl.js'; Migration namespace consumed by run_migrations.
Migration[] import {FACT_MIGRATIONS} from '@fuzdev/fuz_app/db/fact_ddl.js'; Fact + memo migrations.
"\nCREATE TABLE IF NOT EXISTS fact_ref (\n\tsource_hash TEXT NOT NULL REFERENCES fact(hash) ON DELETE CASCADE,\n\ttarget_hash TEXT NOT NULL,\n\tPRIMARY KEY (source_hash, target_hash)\n)" import {FACT_REFS_SCHEMA} from '@fuzdev/fuz_app/db/fact_ddl.js'; fact_ref table — declared dependency edges between facts.
target_hash is not a foreign key (federation: target may live remotely).
"\nCREATE INDEX IF NOT EXISTS idx_fact_ref_target ON fact_ref(target_hash)" import {FACT_REFS_TARGET_INDEX} from '@fuzdev/fuz_app/db/fact_ddl.js'; Reverse lookup: which facts reference a given target?
"\nCREATE TABLE IF NOT EXISTS fact (\n\thash TEXT PRIMARY KEY,\n\tbytes BYTEA,\n\texternal_url TEXT,\n\tcontent_type TEXT,\n\tsize BIGINT NOT NULL,\n\tcreated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n\tCONSTRAINT fact_storage_present CHECK (bytes IS NOT NULL OR external_url IS NOT NULL)\n)" import {FACTS_SCHEMA} from '@fuzdev/fuz_app/db/fact_ddl.js'; fact table — content-addressed byte store.
"\nCREATE TABLE IF NOT EXISTS memo (\n\tfn_id TEXT NOT NULL,\n\tinput_hash TEXT NOT NULL,\n\toutput_hash TEXT NOT NULL,\n\tcreated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n\tPRIMARY KEY (fn_id, input_hash)\n)" import {MEMOS_SCHEMA} from '@fuzdev/fuz_app/db/fact_ddl.js'; memo table — (fn_id, input_hash) → output_hash for memoized computations.