Files
archie/internal/platform/pg/migrations/00038_chat_session_owner.sql
samandCopilot cf6108ad14 feat(chat): conversations belong to their person and act with their access (#2065)
Sessions carry an owner; every chat route serves only the caller's own
conversations (others are 404). Each turn and each approved held action
acts as its owner's principal, checked against the access rules before
judgement, so an operator's chat can't do what the operator can't. Chat is
open to any signed-in person, and the stream sends chat updates only to
the owner.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-20 19:05:20 +11:00

16 lines
729 B
SQL

-- +goose Up
-- A conversation belongs to the person who started it, and its turns act with
-- that person's access. Conversations from before ownership were the shared
-- administrator's, so they go to the system identity the admin token acts as.
ALTER TABLE chat.sessions ADD COLUMN owner_id text;
UPDATE chat.sessions SET owner_id = '00000000-0000-5000-8000-000000000001';
ALTER TABLE chat.sessions ALTER COLUMN owner_id SET NOT NULL;
DROP INDEX chat.sessions_by_org;
CREATE INDEX sessions_by_owner ON chat.sessions (org_id, owner_id, updated_at DESC);
-- +goose Down
DROP INDEX chat.sessions_by_owner;
CREATE INDEX sessions_by_org ON chat.sessions (org_id, updated_at DESC);
ALTER TABLE chat.sessions DROP COLUMN owner_id;