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,35 @@
|
||||
"""The one place audit rows are written (AUD-01, AUD-47).
|
||||
|
||||
Call it inside the same database transaction as the change it records (ADR-53), so a change
|
||||
and its trace commit or roll back together.
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from .models import AuditEntry
|
||||
|
||||
|
||||
def record(
|
||||
action: str,
|
||||
*,
|
||||
actor=None,
|
||||
actor_label: str | None = None,
|
||||
reason: str = "",
|
||||
outcome: str = AuditEntry.Outcome.OK,
|
||||
subject_type: str = "",
|
||||
subject_id: object = "",
|
||||
payload: dict[str, Any] | None = None,
|
||||
) -> AuditEntry:
|
||||
"""Append one audit row. `actor` is the user who acted, or None for the system/worker."""
|
||||
if actor_label is None:
|
||||
actor_label = actor.get_username() if actor is not None else "system"
|
||||
return AuditEntry.objects.create(
|
||||
actor=actor,
|
||||
actor_label=actor_label,
|
||||
action=action,
|
||||
reason=reason,
|
||||
outcome=outcome,
|
||||
subject_type=subject_type,
|
||||
subject_id=str(subject_id),
|
||||
payload=payload or {},
|
||||
)
|
||||
Reference in new issue
Block a user