Files
Memoh/db/queries/channel_routes.sql
T
BBQ ca5c6a1866 refactor(core): restructure conversation, channel and message domains
- Rename chat module to conversation with flow-based architecture
- Move channelidentities into channel/identities subpackage
- Add channel/route for routing logic
- Add message service with event hub
- Add MCP providers: container, directory, schedule
- Refactor Feishu/Telegram adapters with directory and stream support
- Add platform management page and channel badges in web UI
- Update database schema for conversations, messages and channel routes
- Add @memoh/shared package for cross-package type definitions
2026-02-12 15:34:40 +08:00

88 lines
2.1 KiB
SQL

-- name: CreateChatRoute :one
INSERT INTO bot_channel_routes (
bot_id, channel_type, channel_config_id, external_conversation_id, external_thread_id, default_reply_target, metadata
)
VALUES (
sqlc.arg(bot_id),
sqlc.arg(platform),
sqlc.narg(channel_config_id)::uuid,
sqlc.arg(conversation_id),
sqlc.narg(thread_id)::text,
sqlc.narg(reply_target)::text,
sqlc.arg(metadata)
)
RETURNING
id,
sqlc.arg(chat_id)::uuid AS chat_id,
bot_id,
channel_type AS platform,
channel_config_id,
external_conversation_id AS conversation_id,
external_thread_id AS thread_id,
default_reply_target AS reply_target,
metadata,
created_at,
updated_at;
-- name: FindChatRoute :one
SELECT
id,
bot_id AS chat_id,
bot_id,
channel_type AS platform,
channel_config_id,
external_conversation_id AS conversation_id,
external_thread_id AS thread_id,
default_reply_target AS reply_target,
metadata,
created_at,
updated_at
FROM bot_channel_routes
WHERE bot_id = $1
AND channel_type = sqlc.arg(platform)
AND external_conversation_id = sqlc.arg(conversation_id)
AND COALESCE(external_thread_id, '') = COALESCE(sqlc.narg(thread_id), '')
LIMIT 1;
-- name: GetChatRouteByID :one
SELECT
id,
bot_id AS chat_id,
bot_id,
channel_type AS platform,
channel_config_id,
external_conversation_id AS conversation_id,
external_thread_id AS thread_id,
default_reply_target AS reply_target,
metadata,
created_at,
updated_at
FROM bot_channel_routes
WHERE id = $1;
-- name: ListChatRoutes :many
SELECT
id,
bot_id AS chat_id,
bot_id,
channel_type AS platform,
channel_config_id,
external_conversation_id AS conversation_id,
external_thread_id AS thread_id,
default_reply_target AS reply_target,
metadata,
created_at,
updated_at
FROM bot_channel_routes
WHERE bot_id = sqlc.arg(chat_id)
ORDER BY created_at ASC;
-- name: UpdateChatRouteReplyTarget :exec
UPDATE bot_channel_routes
SET default_reply_target = sqlc.arg(reply_target), updated_at = now()
WHERE id = sqlc.arg(id);
-- name: DeleteChatRoute :exec
DELETE FROM bot_channel_routes
WHERE id = $1;