mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-09-03 22:17:04 +00:00
- 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).
17 lines
720 B
SQL
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;
|