Files
goclaw/migrations/000055_vault_scope_consistency_check.up.sql
viettranx 7cfcbbf9db fix(vault): include shared docs in agent read paths (#917)
- Patch vault_search, ListDocuments, CountDocuments, ListTreeEntries to
  include shared docs (agent_id IS NULL) for agents in the tenant
- Keep DELETE/GetDocument/GetByBasename strict (auth-intent)
- Add CHECK invariant vault_documents_scope_consistency (PG migration
  000055 NOT VALID, SQLite triggers v24) to prevent future drift
- Update docs and changelog

Affects PostgreSQL and SQLite (desktop edition).
2026-04-16 14:17:48 +07:00

17 lines
720 B
SQL

-- Scope/ownership invariant for vault_documents.
-- personal → agent_id NOT NULL, team_id NULL
-- team → team_id NOT NULL, agent_id NULL
-- shared → both NULL
-- custom → no constraint (user-defined scopes)
ALTER TABLE vault_documents
ADD CONSTRAINT vault_documents_scope_consistency
CHECK (
(scope = 'personal' AND agent_id IS NOT NULL AND team_id IS NULL) OR
(scope = 'team' AND team_id IS NOT NULL AND agent_id IS NULL) OR
(scope = 'shared' AND agent_id IS NULL AND team_id IS NULL) OR
scope = 'custom'
) NOT VALID;
-- Ops step (run after audit cleanup):
-- ALTER TABLE vault_documents VALIDATE CONSTRAINT vault_documents_scope_consistency;