PR #294 · pramaan-io/pramaan-functions · merged 2026-06-10
The audit log is the firm's witness — and the window to reshape it is now.
Partition-ready PK, cursor-aligned seq, scope chain, and a ledger no one can erase.
Lock-it-later is the lie. The cheap window is while the table is near-empty.
The fix — Number every entry, scope every event, lock the ledger before the questions arrive.
sequenceDiagram autonumber participant schema as Alembic migration participant data as Existing rows participant db as Postgres guarantees schema->>data: Add new columns (nullable / defaulted) schema->>data: Backfill seq in (created_at, id) order schema->>data: Attach seq identity, continue from max+1 schema->>db: Add scope-chain + agent CHECKs schema->>db: REVOKE UPDATE, DELETE + BEFORE trigger schema-->>db: Add seq-aligned firm-leading indexes
| Method | in → out | what it does |
|---|---|---|
upgrade | () → None | |
downgrade | () → None |
Alembic migration evolving the audit log — adds partition-ready PK, seq identity with deterministic backfill, scope CHECKs, append-only enforcement, and firm-leading indexes.
| new method | signature |
|---|---|
upgrade | () → None |
downgrade | () → None |
revision : strdown_revision : str | Sequence[str] | Nonebranch_labels : str | Sequence[str] | Nonedepends_on : str | Sequence[str] | Nonesrc/domains/audit_log/entity.py+189 −10Audit log ORM entity — adds actor_label, category, scope chain, agent_run_id, and seq fields so the model mirrors the evolved schema with legacy rows still valid.
actor_label : str | Nonecategory : str | Nonesubject_label : str | Nonearea : str | Nonematter_id : UUID | Noneproceeding_id : UUID | Nonefiling_id : UUID | Nonedocument_id : UUID | Noneagent_run_id : UUID | Noneon_behalf_of_user_id : UUID | Nonetrigger : str | Noneseq : int | None