RFC-025: A project's data in SQLite, a project's choice¶
- Status: Accepted (2026-11-06), minimal version first (owner). The first version moved a run's outputs and rows only; that part is built and is part of this one. Owner, 2026-11-06: "project has file mode by default but easy to change to sqlite"; "one database in project for all its data"; "catalog reads from it all data and inspector as well"; "SQLite mode is SQLite mode"; "minimal version first".
- Authors: Marko Dragoljevic
- Related: RFC-024 (one reader for outputs, the pattern repeated here);
research/internal/PLAN_0.8.0.mdS0
Abstract¶
A project keeps its data as files, as today, unless its config.yaml says store: sqlite. Then everything under
data/ lives in one SQLite database, data/project.sqlite, and every command, the catalog and the inspector read and
write it there. Python code is never in the database. evh data-migrate --to sqlite|files moves a project either way.
SQLite is in Python's standard library: no dependency.
Design¶
- The setting:
store: sqlitein the project'sconfig.yaml, orEVAL_STORE=sqlite(wins over the file). Defaultfiles. - One module,
_store.py, reads and writes everything underdata/, addressed by its path relative todata/(datasets/tickets_v1.json,runs/arm_v1_x/metrics.json). The files store is the filesystem as today. Every module moves onto it, and a test fails on a path underdata/built anywhere else. - The database:
data/project.sqlite, write-ahead logged. A table of files (path, bytes, sha256), and a run's outputs and rows in the per-item tables already built (one committed insert per output and row). - Either files or the database, never both (owner, 2026-11-06): in SQLite mode nothing under
data/is a file. Python code is not data and is never in the database: a project in SQLite mode keeps its code outsidedata/, in git, and names it by path (path.py:Class, as dataset sources already allow).data-migrate --to sqliterefuses whiledata/holds a.pyfile, naming each. - Moving:
evh data-migrate --to sqlite|files; every file read back and compared by sha256 before the old copy is removed. - Getting data in: in SQLite mode a person's settings (a goal, a config) get into the database through the data
page or
evh data-put(PRD-016, UXS-004; the owner asked for it after first choosingdata-migratealone, 2026-11-06), and a folder of files throughdata-migrate --to sqlite; every command over an API comes with RFC-026. The harness's own writes (runs, datasets it creates, labels, verdicts) go to the database directly. - validate in SQLite mode skips the checks that ask git what is committed (nothing in the database is in git) and says so. A release copies the database with a hidden dataset's text removed.
Not in scope (minimal version)¶
Anything else: no settings screen, no history, no export or import, no extra commands.
Testing¶
- The store's tests on both stores;
data-migratethere and back on a copy of this repository'sdata/, every file byte-identical. - The full suite (
make verify) on the files store. On the sqlite store, what reads a project: this repository'sdata/moved into a database in a separate copy, through validate, the catalog, the site check and the report checks. - Every test file on the sqlite store too:
make stores-check(tools/store_matrix.py, the CI jobstores), each file in its own process withEVAL_STORE=sqlite. A test reads and writes its project's data throughtests/_runstore.py, so the same checks hold in both stores. A file that reads this repository's own committed data, or a behaviour that is files by definition (git, the layout before 0.8.0), pins itself to files and says why at its top. First run (2026-11-08): 61 of 97 files failed on sqlite only; converting them found five product bugs, each fixed with the failing test first:dataset-create --source-dirlisted a source folder in the database with pathlib (nothing matched),evh self-testcopied its fixtures onto a disk that has nodata/folders,initmade nodata/and still listed folders, a config'sadapter: ../../x.pyclimbed through a folder that is only a key, and a release published the texts of a reference whose manifest says they are not redistributed (git kept them out for files; nothing did in the database). - S1's bench on both stores, before S2 (2026-11-06; PLAN_0.8.0 S1): the same times within a few percent, the 10,000-item catalog 1,576 s as files and 1,584 s in the database.
Built before this version, replaced by it¶
A run's outputs and rows behind _outputs.py in either store (kept); a database per runs folder, a .store-id token
per run directory, runs.store/EVAL_RUNS_STORE and run-migrate --to (replaced by the above).
As built (0.8.0)¶
_store.pydoes every read, write, listing and delete of a path. A path underdata/in the sqlite store is a row ofdata/project.sqlite(tablefiles: path, bytes, sha256, mtime); every other path, and every path in the files store, is the disk, as pathlib would do it, so moving the about 950 calls inscripts/,harness/tools/,site/andexamples/onto it changed nothing in files mode. The move was an AST-located rewrite (formatting and comments kept).tests/test_store.pyreads every file ofscripts/(withsources/andimporters/),harness/tools/,site/andexamples/and fails on path I/O (the pathlib andoscalls,shutil,glob, a temporary file made in a given directory) in any file but the store and the ones it names with why:_store,_outputs(its files store is the disk by definition),data_migrate,run_migrate,_common(finding the project before any store exists), and files that never touch a project'sdata/(the site's own build, packaging, the file a person names to a source or an importer, a prompt beside its code). Until the review of 2026-11-06 it readscripts/alone and missedrename,rmdirandtempfile(dir=): label sets and capture restore wrote through a temporary folder on disk underdata/and failed in SQLite mode; they build in_store.stagingand put it in place with_store.adopt.- A run is its key under
data/; its outputs and rows are the per-item tables built in the first version._store.rmtreeof a run removes its outputs and rows with its files, so a run made again at the same path starts empty. A run outsidedata/(a scratch folder) is the disk's, as every path outsidedata/is. - Per-item rows are tables since format 7 (RFC-033,
ADR-0030). The "per-item tables" above were a text value per line,
a byte-for-byte mirror of
predictions.jsonl. They are nowscore_sets,score_rows,score_values,call_factsandmetrics, anddata-migratecompares a score set's rows as canonical text, not as bytes. The files store, thefilestable andoutputsare as described here. - Never both: V23 names a
data/project.sqlitebeside files, and files underdata/beside the database. V7 reads git and says why it does not apply; V9's file listing reads git too, and in SQLite mode V9 checks what the database is the record of instead (RFC-033): every score set with a record has rows, as many as itsn_items, and each committed arm meets its floor. - The release reads the store and wrote the same files layout from either store, a hidden dataset's text left
out. (The design above said the release copies the database; a deployment that reads a database needed the prod
deploy changed.) Superseded in 0.8.0 by RFC-032 step 9: the release is one sealed SQLite database, opened read-only
on the box (
EVALS_STORE=filesstill makes a files release). catalog-serveserves the data tree from the database.- Verified on this repository's data:
data-migratethere and back, 12,001 files byte-identical; on the database,validatepasses,check_report_claimsverifies 200/200 claims, the site check is green, and the catalog's 928 pages equal the files catalog's but for the build time (one JSON file's keys in another order, equal content). - The skills on both stores (owner, 2026-11-08: "A"): their blocks put settings in with
evh data-putand read them withevh data-show --text, nevercpondata/, and commit with--allow-empty;test_skills.pyruns them in both stores. "Named in advance" is told from git, so it needs a files project in git; in the database store the run records it as not determinable, and the skill says so. - Not covered: the browser tests and the inspector's budget run on files only; the examples'
fetch.pyscripts write sources as files underdata/, which in SQLite modedata-migratethen moves in.