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>
25 lines
922 B
Python
25 lines
922 B
Python
"""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)]
|