fix(state): correct audit backfill scoping and policy write races

This commit is contained in:
sam committed 2026-10-25 20:59:04 +11:00
1 parent e3478ec400
commit b397329de0
6 files changed
+120 -45

No files matched your search

@@ -22,6 +22,12 @@ WHERE level = $1 AND org_id = $2 AND workspace_id = $3 AND object_kind = $4
AND object_id = $5 AND policy_id = $6
RETURNING text;
-- name: LockPolicyWrite :exec
-- Serialises concurrent writes to one policy key. SELECT FOR UPDATE cannot
-- lock a row that does not exist yet, so without this two concurrent creates
-- both read no previous row and the second is audited as a create.
SELECT pg_advisory_xact_lock(hashtextextended(sqlc.arg(key)::text, 0));
-- name: AccessPolicyText :one
SELECT text FROM access_policies
WHERE level = $1 AND org_id = $2 AND workspace_id = $3 AND object_kind = $4