M1 · Strato dati #116

Merged
Alby96 merged 1 commits from feat/7-strato-dati into main 2026-11-11 13:18:05 +01:00
Owner

Milestone M1 — Strato dati (v0.1.0).

Closes #7

Chiude anche #8, #9, #10, #11, #12, #13, #14 (Gitea legge solo il primo riferimento: le altre vanno chiuse a mano dopo il merge).

Cosa contiene

  • Micro-ORM interno (Khaemhat.Data):
    • mappe EntityMap<T>;
    • query tipizzate Query.For<T>().Where(...);
    • SqlFragment con ogni valore interpolato trasformato in parametro;
    • unit of work con transazioni;
    • repository con colonne di audit e row_version (ConcurrencyException);
    • tentativi automatici sugli errori transitori.
  • Provider SQLite:
    • tabelle STRICT e WAL;
    • decimali esatti come interi scalati per 10^6;
    • LIKE senza distinzione di maiuscole, lettere accentate comprese;
    • scritture serializzate.
  • Provider PostgreSQL 16+:
    • numeric(19,6), timestamptz, jsonb, ILIKE;
    • advisory lock;
    • creazione ed eliminazione dei database;
    • informazioni sul server.
  • DatabaseUrl: configurazione da URL postgres:// e sqlite://. La password non compare mai nei messaggi.
  • Migrazioni in C#:
    • schema_version con checksum;
    • una transazione per migrazione, sotto lock;
    • rifiuto delle versioni sconosciute;
    • tabelle sys_companies e sys_settings.
  • CompanyRegistry: salva l'URL del database cifrato con SecretProtector. La cifratura è AES-256-GCM, con chiave derivata via HKDF e scopo come AAD.
  • Strumenti: tools/Khaemhat.DataModelTool, scripts/gen-datamodel.sh e scripts/new-migration.sh. La sezione Schema attuale di docs/DATA-MODEL.md è generata e verificata da un test.
  • ADR 0018: scostamenti dalle firme di SPEC §5.1.
  • Documentazione aggiornata: DATA-MODEL, ARCHITECTURE, SECURITY, DEVELOPMENT, CHANGELOG, STATUS e le pagine wiki Modello-dati e Changelog.

Verifica

  • scripts/build.sh è verde con warning come errori, e l'allowlist dei pacchetti è OK.
  • Test su SQLite, in locale:
    • Data: 85 superati;
    • Infrastructure: 16;
    • Core: 11;
    • Web: 12.
  • I 21 test PostgreSQL in locale risultano saltati, perché Docker non è disponibile. Girano in CI con il job postgres (16 e 17), avviato a mano sul ramo.
  • Misura di riferimento SQLite con 100.000 righe: inserimento in 5,6 s, lettura completa in 0,9 s, pagina filtrata in 17 ms.

🤖 Generated with Claude Code

Milestone **M1 — Strato dati** (v0.1.0). Closes #7 Chiude anche #8, #9, #10, #11, #12, #13, #14 (Gitea legge solo il primo riferimento: le altre vanno chiuse a mano dopo il merge). ## Cosa contiene - **Micro-ORM interno** (`Khaemhat.Data`): - mappe `EntityMap<T>`; - query tipizzate `Query.For<T>().Where(...)`; - `SqlFragment` con ogni valore interpolato trasformato in parametro; - unit of work con transazioni; - repository con colonne di audit e `row_version` (`ConcurrencyException`); - tentativi automatici sugli errori transitori. - **Provider SQLite:** - tabelle `STRICT` e WAL; - decimali esatti come interi scalati per 10^6; - LIKE senza distinzione di maiuscole, lettere accentate comprese; - scritture serializzate. - **Provider PostgreSQL 16+:** - `numeric(19,6)`, `timestamptz`, `jsonb`, `ILIKE`; - advisory lock; - creazione ed eliminazione dei database; - informazioni sul server. - **`DatabaseUrl`:** configurazione da URL `postgres://` e `sqlite://`. La password non compare mai nei messaggi. - **Migrazioni in C#:** - `schema_version` con checksum; - una transazione per migrazione, sotto lock; - rifiuto delle versioni sconosciute; - tabelle `sys_companies` e `sys_settings`. - **`CompanyRegistry`:** salva l'URL del database cifrato con `SecretProtector`. La cifratura è AES-256-GCM, con chiave derivata via HKDF e scopo come AAD. - **Strumenti:** `tools/Khaemhat.DataModelTool`, `scripts/gen-datamodel.sh` e `scripts/new-migration.sh`. La sezione *Schema attuale* di `docs/DATA-MODEL.md` è generata e verificata da un test. - **ADR 0018:** scostamenti dalle firme di SPEC §5.1. - **Documentazione aggiornata:** DATA-MODEL, ARCHITECTURE, SECURITY, DEVELOPMENT, CHANGELOG, STATUS e le pagine wiki *Modello-dati* e *Changelog*. ## Verifica - `scripts/build.sh` è verde con warning come errori, e l'allowlist dei pacchetti è OK. - Test su SQLite, in locale: - Data: 85 superati; - Infrastructure: 16; - Core: 11; - Web: 12. - I 21 test PostgreSQL in locale risultano saltati, perché Docker non è disponibile. Girano in CI con il job `postgres` (16 e 17), avviato a mano sul ramo. - Misura di riferimento SQLite con 100.000 righe: inserimento in 5,6 s, lettura completa in 0,9 s, pagina filtrata in 17 ms. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Alby96 added this to the M1 — Strato dati · v0.1.0 milestone 2026-11-11 13:11:55 +01:00
Alby96 added 1 commit 2026-11-11 13:11:55 +01:00
feat: data layer with SQLite and PostgreSQL providers, migrations and encrypted company registry (M1)
CI / Build and test (SQLite) (pull_request) Successful in 45s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 3s
CI / Docker image (pull_request) Successful in 51s
738c43ba0a
Every later milestone stores its data through this layer, so it has to behave the same on both engines and be safe
by construction:

- Khaemhat.Data: explicit entity maps, typed queries over a safe expression subset, SqlFragment where every
  interpolated value becomes a parameter, unit of work with transactions, repositories with audit columns and
  optimistic concurrency on row_version, retries on transient errors.
- SQLite provider (STRICT tables, WAL, exact decimals as integers scaled by 10^6, Unicode case-insensitive LIKE,
  serialised writes) and PostgreSQL 16+ provider (numeric(19,6), timestamptz, jsonb, advisory locks, database
  creation and server info). Databases are configured from postgres:// and sqlite:// URLs whose password never
  appears in messages.
- C# migrations with system and company catalogues, schema_version with checksums, one transaction per migration
  under a lock, refusal of unknown applied versions; first system tables sys_companies and sys_settings.
- CompanyRegistry stores each company's database URL encrypted with the instance key (AES-256-GCM, HKDF-derived key,
  purpose as associated data), so a copied row cannot be read for another company.
- tools/Khaemhat.DataModelTool, scripts/gen-datamodel.sh and scripts/new-migration.sh: the current schema section of
  docs/DATA-MODEL.md is generated from the migrations and a test fails when it is stale.
- C# 14 binds array.Contains to MemoryExtensions over spans; the query translator unwraps the span conversion.
- Tests run every data scenario on SQLite and PostgreSQL (PostgreSQL in CI); ADR 0018 records where the contracts
  differ from SPEC 5.1. Docs, wiki, changelog and status updated.

Closes #7, #8, #9, #10, #11, #12, #13, #14

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Alby96 merged commit 6eef15c487 into main 2026-11-11 13:18:05 +01:00
Alby96 deleted branch feat/7-strato-dati 2026-11-11 13:18:06 +01:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: BalboSoft/Khaemhat#116