Files
Enterprise-Knowledge-Base/migrations/versioned/000028_im_thread_session.up.sql
T
ochan.kwon 2d5782992e [NELO-1102] feat(im): add thread-based session mode for IM channels
Add session_mode ("user" | "thread") to IM channel config. In thread
mode, each message thread gets its own session, enabling multi-user
collaboration within the same thread context.

Backend:
- Add SessionMode type constants and validation
- Add ThreadID field to IncomingMessage and ChannelSession
- Split resolveSession into resolveUserSession/resolveThreadSession
- Update makeUserKey to include threadID only in thread mode
- Extract ThreadID in Slack, Mattermost, Feishu, Telegram adapters
- Add message_thread_id to Telegram SendReply/StartStream for Forums
- DB migration 000028: session_mode column + thread_id column + index

Frontend:
- Add session_mode radio group to IMChannelPanel dialog
- Auto-reset session_mode when switching to non-thread platform
- Show thread badge on channel card for thread-mode channels
- Add i18n keys for en-US, ko-KR, zh-CN, ru-RU
2026-03-30 10:43:14 +08:00

34 lines
1.4 KiB
SQL

-- Migration: 000028_im_thread_session
-- Description: Add thread-based session mode support for IM channels
DO $$ BEGIN RAISE NOTICE '[Migration 000028] Adding thread session support'; END $$;
-- 1. im_channels: add session_mode column
ALTER TABLE im_channels
ADD COLUMN IF NOT EXISTS session_mode VARCHAR(20) NOT NULL DEFAULT 'user';
-- 2. CHECK constraint (separate statement: ADD COLUMN IF NOT EXISTS does not support inline CONSTRAINT)
DO $$ BEGIN
ALTER TABLE im_channels
ADD CONSTRAINT chk_im_channels_session_mode
CHECK (session_mode IN ('user', 'thread'));
EXCEPTION WHEN duplicate_object THEN NULL;
END $$;
COMMENT ON COLUMN im_channels.session_mode IS
'Session resolution mode: user (per user+chat, default) or thread (per thread)';
-- 3. im_channel_sessions: add thread_id column
ALTER TABLE im_channel_sessions
ADD COLUMN IF NOT EXISTS thread_id VARCHAR(128) NOT NULL DEFAULT '';
COMMENT ON COLUMN im_channel_sessions.thread_id IS
'Platform thread identifier for thread-based sessions. Empty for user-mode sessions.';
-- 4. Unique index for thread-mode session lookup
-- Includes chat_id because Telegram message_thread_id is per-chat (topic ID within a group).
CREATE UNIQUE INDEX IF NOT EXISTS idx_channel_thread_lookup
ON im_channel_sessions (platform, chat_id, thread_id, tenant_id)
WHERE deleted_at IS NULL AND thread_id != '';
DO $$ BEGIN RAISE NOTICE '[Migration 000028] Thread session support added'; END $$;