A2: lottery models and database constraints (WEB-04, ADR-10, ADR-15, ADR-22, DAT-76..79, AUD-47)
LotteryConfig (single row, parameters and the three pause switches), Round (single active round, own rules, split within the pool), Participation (one bet per player and round, unique draw position), Movement (signed ledger, idempotency key per player), ChainTransaction and an append-only AuditEntry enforced by the model and by SQLite triggers. Every foreign key is PROTECT. One test per constraint, each checked to hit the intended constraint. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fc23a75c9b
commit
0eba7bcfe6
12 files changed
+1139
-4
No files matched your search
@@ -685,3 +685,16 @@ nome tra parentesi quadre nel log è il modulo (`app.rounds.scheduler`, ecc.).
|
||||
| ERROR | `app.tx.reconcile` | `round N payout tx … vanished — round needs operator attention` | Pagamento abbandonato; il nuovo tentativo automatico parte da solo |
|
||||
| ERROR | `app.auth.security` | `stored password hash is unparseable …` | Hash di password corrotto nel database: quell'utente non può accedere |
|
||||
| ERROR (con traccia) | `app.main` | `Unhandled error on …` | Errore 500 su una richiesta ([AUD-35]) |
|
||||
|
||||
## Registro di audit del sito Django
|
||||
|
||||
- **[AUD-47]** **Registro in sola aggiunta, scritto da un solo punto.** `AuditEntry` registra data, attore
|
||||
(l'utente, e il suo nome di allora, oppure `system`), azione, motivo, esito (`ok`, `denied`, `error`),
|
||||
oggetto e dati. Si scrive solo con `apps/lottery/audit.py:record`, **nella stessa transazione** del
|
||||
cambiamento che registra ([ADR-53](adr/ADR-53-registro-audit-solo-aggiunta-stessa-transazione.md)): se il cambiamento
|
||||
si annulla, si annulla anche la riga. Il modello rifiuta modifiche e cancellazioni (`save` su riga esistente,
|
||||
`delete`, `QuerySet.update`/`delete`) e **il database le rifiuta a sua volta** con trigger SQLite
|
||||
(`BEFORE UPDATE`/`BEFORE DELETE`), quindi nemmeno un `UPDATE` SQL diretto riscrive la storia.
|
||||
*Stato:* implementato (A2) ·
|
||||
*Codice:* `apps/lottery/audit.py:record`, `apps/lottery/models.py:AuditEntry`, `apps/lottery/migrations/0002_audit_append_only_triggers.py` ·
|
||||
*Test:* `tests/django/test_models.py::test_an_audit_row_cannot_be_changed_with_raw_sql_either`, `test_the_audit_is_written_in_the_same_transaction_as_the_change`
|
||||
Reference in new issue
Block a user