-- +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;