| 1 | -- Sensitive actions: who did what, to what, when, and from where. Rows are |
| 2 | -- only ever added: transfer_app may INSERT, and nothing else, not even SELECT. |
| 3 | CREATE TABLE audit_log ( |
| 4 | id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
| 5 | at timestamptz NOT NULL DEFAULT now(), |
| 6 | actor text NOT NULL, -- who: a user's ID, or a database role |
| 7 | action text NOT NULL, -- what, like transfer.approve |
| 8 | target text NOT NULL, -- to what: a transfer's ID, say |
| 9 | details jsonb NOT NULL DEFAULT '{}', |
| 10 | client text NOT NULL DEFAULT '', -- from where: the service that called us |
| 11 | request_id text NOT NULL DEFAULT '', |
| 12 | trace_id text NOT NULL DEFAULT '' |
| 13 | ); |
| 14 | REVOKE ALL ON audit_log FROM transfer_app; |
| 15 | GRANT INSERT ON audit_log TO transfer_app; |
| 16 | |
| 17 | -- And a transfer's history, and every risk decision, are only ever added to. |
| 18 | REVOKE UPDATE, DELETE ON transfer_steps, risk_decisions FROM transfer_app; |