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
@@ -0,0 +1,24 @@
|
||||
"""The audit log is append-only in the database too (AUD-47).
|
||||
|
||||
Whatever the code does — a raw `UPDATE`, a `QuerySet._raw_delete`, a shell session — a row of
|
||||
`lottery_auditentry` can only be inserted. SQLite syntax; PostgreSQL gets its own migration the
|
||||
day it replaces SQLite (ADR-55).
|
||||
"""
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
CREATE = [
|
||||
"""CREATE TRIGGER lottery_audit_no_update BEFORE UPDATE ON lottery_auditentry
|
||||
BEGIN SELECT RAISE(ABORT, 'audit log is append-only'); END""",
|
||||
"""CREATE TRIGGER lottery_audit_no_delete BEFORE DELETE ON lottery_auditentry
|
||||
BEGIN SELECT RAISE(ABORT, 'audit log is append-only'); END""",
|
||||
]
|
||||
DROP = [
|
||||
"DROP TRIGGER IF EXISTS lottery_audit_no_update",
|
||||
"DROP TRIGGER IF EXISTS lottery_audit_no_delete",
|
||||
]
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("lottery", "0001_initial")]
|
||||
operations = [migrations.RunSQL(sql=CREATE, reverse_sql=DROP)]
|
||||
Reference in new issue
Block a user