feat(state): audit access resets, org and EDA writes

This commit is contained in:
sam committed 2026-10-25 21:10:38 +11:00
1 parent 0cccef6bb7
commit 99b1f8a2d9
12 files changed
+758 -167

No files matched your search

@@ -33,7 +33,14 @@ JOIN identities i ON i.id = m.identity_id
WHERE m.org_id = $1
ORDER BY m.created_at, m.identity_id, m.workspace_id;
-- name: RemoveMembership :exec
-- name: MembershipRole :one
-- The current role of the membership EnsureMembership/RemoveMembership targets,
-- read in the same transaction so the audit row carries both sides.
SELECT role FROM memberships
WHERE identity_id = sqlc.arg(identity_id) AND org_id = sqlc.arg(org_id)
AND COALESCE(workspace_id, '') = sqlc.arg(workspace_id)::text;
-- name: RemoveMembership :execrows
-- The workspace is matched through the same COALESCE the unique index uses, so
-- an org-wide membership (NULL) and the empty string are the same target.
DELETE FROM memberships
@@ -46,6 +53,9 @@ SELECT identity_id, org_id FROM org_agents WHERE org_id = $1 ORDER BY identity_i
SELECT identity_id, org_id, workspace_id, role, created_at
FROM memberships WHERE identity_id = $1 ORDER BY created_at, org_id;
-- name: AgentAssignmentOrg :one
SELECT org_id FROM org_agents WHERE identity_id = $1;
-- name: UpsertAgentAssignment :exec
INSERT INTO org_agents (identity_id, org_id) VALUES ($1, $2)
ON CONFLICT (identity_id) DO UPDATE SET org_id = excluded.org_id;