Files
plm-lottery/apps/lottery/migrations/0002_audit_append_only_triggers.py
T

24 lines
922 B
Python
Raw Normal View History

"""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)]