Skip to content

feat(db): sqlite schema, append-only triggers, and typed accessors (T03) - #4

Merged
prateekchaplot merged 4 commits into
mainfrom
arch/caliper/t03
Nov 15, 2026
Merged

prateekchaplot merged 4 commits into
mainfrom
arch/caliper/t03

Conversation

@prateekchaplot

Copy link
Copy Markdown
Owner

Task T03 from docs/ARCHITECTURE.md §14.2 (spec §7.3, §8).

What

  • src/caliper/schema.sql: all global tables (§8.2–§8.8) with CHECK constraints, indexes, and the §8.9 append-only triggers (UPDATE blocked on runs once terminal; unconditional UPDATE/DELETE blocks on run_results/spot_checks/feedback; DELETE blocked on all four; requests + children deliberately editable; chunks trio deliberately mutable per FR-02).
  • src/caliper/db.py: connect() (sqlite-vec loaded, WAL, foreign keys), idempotent ensure_schema() with schema_meta version guard, ensure_chunks_tables(conn, fp8) (chunks + external-content FTS5 + vec0 float[768] cosine + sync triggers), typed accessors for every table. db is a leaf — no config import, no business logic.

Decisions (recorded in docs/TASKS.md Notes)

  1. §8.3 "contentless external-content" → external-content FTS5 with sync triggers.
  2. Extra trigger: runs rows must be born in status running.
  3. ingest_runs upsert = one row per fingerprint, resets finished_at/pages_*.
  4. Chunk/embedding accessors added for T07/T08 (insert_chunks, get_chunks, delete_chunks, insert_chunk_embeddings).

Verification

uv run pytest 63 passed (25 new: 19 unit, 6 integration for triggers); ruff check, ruff format --check, mypy strict all clean. sqlite-vec loads on Windows (vec_version() called in tests); vec0 cosine distance verified ≈ 0 on a unit vector.

Dependent tasks (per §14.4)

T07 (ingest orchestration) uses ensure_chunks_tables/insert_chunks/delete_chunks; T09 (retrieval) queries the frozen chunks_<fp8> trio shape; T13–T15 read the runs/run_results/spot_checks accessors. Dependents: re-run integration tests after this merges.

Implements ARCHITECTURE.md §7.3 and §8: global tables, schema_meta versioning, idempotent ensure_schema, per-fingerprint chunks trio (external-content FTS5 + vec0 float[768] cosine) created on demand, append-only enforcement on runs/run_results/spot_checks/feedback, and typed accessors for every table. sqlite-vec loaded in connect(); WAL + foreign keys on. Depends on T02 (fp8 suffixes); names dependent tasks T07-T15.
@prateekchaplot
prateekchaplot merged commit b643290 into main Nov 15, 2026
1 check passed
@prateekchaplot
prateekchaplot deleted the arch/caliper/t03 branch November 15, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant