✅ fresh
last synced 2026-09-29T21:12:19.681221+00:00 · coverage 100% (
db)Validation by Beadloom
doc_sync— same source assync-check.
DB (component)
Internal building block of the infrastructure domain.
Source: src/beadloom/infrastructure/db.py
Overview
The domain-agnostic SQLite layer: connection management, schema creation, and the meta key/value helpers. Every other domain reads and writes through this single, lowest-layer module — it owns the database file lifecycle and the table definitions the rest of Beadloom depends on.
Public surface
open_db(db_path)— open a SQLite connection with WAL mode, foreign keys, and asqlite3.Rowrow factory.open_db_readonly(db_path)— open an EXISTING database through themode=roURI withquery_only=ON, leaving the file byte-identical; raisesFileNotFoundErrorrather than creating one.open_dbsetsjournal_mode=WAL, which rewrites the header of a database that is not already in WAL — so a verb that only reads still changed the artifact it reported on (BDL-UX #147).connection(db_path)/readonly_connection(db_path)— context-manager wrappers over the two factories.create_schema(conn)— create all tables/indexes and runensure_schema_migrations.ensure_schema_migrations(conn)— apply the additive, idempotent migrations (thelifecyclecolumn +externalCHECK rebuild,edges.contract_key,foreign_edges, the free-formkindrebuild,sync_state.baseline_source,sync_state.file_symbols_hash(added after the table rebuilds, which copy an explicit column list and would drop a column added before them), the four-verdictsync_state.statusrebuild,declared_docs, thedocs.spacecolumn, …).docs.spacerecords which documentation space a file belongs to —to_be,as_isorworking— and defaults toas_is, which is what every row in a pre-BDL-061 index already was.- The test-file tables (BDL-074 C1), created by the schema script with
CREATE TABLE IF NOT EXISTS, so they are additive andSCHEMA_VERSIONis unchanged:test_files(path, kind, ref_id, placement, test_count, file_hash),test_imports(file_path, line_number, import_path, resolved_ref_id)in thecode_importsshape, andtest_overrides(ref_id, prefix)for thetests:prefixes a node declares. Indexesidx_test_files_refandidx_test_imports_file. Tests live here and never incode_symbols,code_importsorfile_index, so they do not become code. get_meta(conn, key, default=None)/set_meta(conn, key, value)— themetakey/value helpers.SCHEMA_VERSION— the schema version constant (currently"4").
Collaborators
The lowest layer: every domain reads and writes through it. The full table inventory (nodes/edges/foreign_edges, docs/chunks, declared_docs, code_symbols, sync_state, test_files/test_imports/test_overrides, health/graph snapshots, FTS5 search, rules, …) and the migration detail live in the infrastructure README.
Component doc (BDL-051). Public surface verified against
db.py.