docs(i4): brief + plan + golden fixture builder (I4)
Session brief (scope, non-goals, pinned SQL type/number decisions, verification) + TDD plan + build_fixture.py (regenerates the sqlite golden; the committed db bytes need not reproduce — the golden compares the derived bundle).
This commit is contained in:
parent
4f45fe6037
commit
1b7612b22d
3 changed files with 201 additions and 0 deletions
|
|
@ -0,0 +1,53 @@
|
|||
"""Build the I4 sql golden fixture: examples/ingest-golden-sql/fixture/portefolje.sqlite
|
||||
+ ingested-at.txt.
|
||||
|
||||
Regenerable; the committed db BYTES need not be reproduced bit-for-bit — the golden test
|
||||
compares the derived bundle (from db CONTENT via the manifest queries), not the db file.
|
||||
Parameterized inserts keep the backslash/pipe escape-probe values exact (no SQL string-literal
|
||||
surprises: 'c:\\temp' would be a tab if written as a Python literal). The data is chosen to
|
||||
discriminate a typed §5 implementation from naive ones — SQL NULL, an integral REAL (4200.0),
|
||||
non-integral REALs, and pipe/backslash text.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
GOLDEN = Path(__file__).resolve().parents[3] / "examples" / "ingest-golden-sql"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
fixture = GOLDEN / "fixture"
|
||||
fixture.mkdir(parents=True, exist_ok=True)
|
||||
db = fixture / "portefolje.sqlite"
|
||||
if db.exists():
|
||||
db.unlink()
|
||||
conn = sqlite3.connect(db)
|
||||
try:
|
||||
conn.execute("CREATE TABLE costs (id INTEGER, item TEXT, amount REAL, note TEXT)")
|
||||
conn.executemany(
|
||||
"INSERT INTO costs VALUES (?, ?, ?, ?)",
|
||||
[
|
||||
(1, "LED-armatur", 1200.5, "godkjent"),
|
||||
(2, "sensor", 89.9, None), # NULL → empty cell (discriminator)
|
||||
(3, "kabel", 4200.0, "rest"), # integral REAL → "4200.0", not "4200"
|
||||
],
|
||||
)
|
||||
conn.execute("CREATE TABLE meta (k TEXT, v TEXT)")
|
||||
conn.executemany(
|
||||
"INSERT INTO meta VALUES (?, ?)",
|
||||
[
|
||||
("owner", "anlegg | drift"), # pipe → escaped \|
|
||||
("path", "c:\\temp"), # backslash → escaped \\
|
||||
],
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
(GOLDEN / "ingested-at.txt").write_bytes(b"2026-07-04T12:00:00Z\n")
|
||||
print(f"built {db} ({db.stat().st_size} bytes) + ingested-at.txt")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue