Initial commit: 风影 OA 全栈源码(API/Web/Flutter/IM)
含 Phase 1.1 IM seq 排序、断线重连、多端已读同步与微信式语音转文字 UI。 排除 node_modules、构建产物、安装包与 .env 密钥。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
-- Phase 1.1: 会话级单调递增 seq,用于消息排序、去重与断线补拉
|
||||
ALTER TABLE "ImConversation" ADD COLUMN IF NOT EXISTS "nextSeq" INTEGER NOT NULL DEFAULT 1;
|
||||
|
||||
ALTER TABLE "ImMessage" ADD COLUMN IF NOT EXISTS "seq" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE "ImReadCursor" ADD COLUMN IF NOT EXISTS "lastReadSeq" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
-- 按 createdAt 回填历史 seq
|
||||
WITH ranked AS (
|
||||
SELECT id, ROW_NUMBER() OVER (PARTITION BY "conversationId" ORDER BY "createdAt", id) AS rn
|
||||
FROM "ImMessage"
|
||||
)
|
||||
UPDATE "ImMessage" m SET seq = ranked.rn FROM ranked WHERE m.id = ranked.id;
|
||||
|
||||
UPDATE "ImConversation" c
|
||||
SET "nextSeq" = COALESCE((
|
||||
SELECT MAX(seq) + 1 FROM "ImMessage" WHERE "conversationId" = c.id
|
||||
), 1);
|
||||
|
||||
UPDATE "ImReadCursor" rc
|
||||
SET "lastReadSeq" = COALESCE((
|
||||
SELECT MAX(seq) FROM "ImMessage" m
|
||||
WHERE m."conversationId" = rc."conversationId" AND m."createdAt" <= rc."lastReadAt"
|
||||
), 0);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "ImMessage_conversationId_seq_idx" ON "ImMessage"("conversationId", "seq");
|
||||
Reference in New Issue
Block a user