feat: 实现实时匿名会话
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
-- Task 7 chat identity snapshots, query and delivery indexes.
|
||||
ALTER TABLE "messages" ADD COLUMN "sender_public_id" UUID;
|
||||
UPDATE "messages" AS m
|
||||
SET "sender_public_id" = p."public_id"
|
||||
FROM "anonymous_profiles" AS p
|
||||
WHERE p."account_id" = m."sender_id";
|
||||
-- Legacy/seed rows may predate anonymous profiles. Preserve an unlinkable
|
||||
-- snapshot instead of deriving or exposing the private account identifier.
|
||||
UPDATE "messages"
|
||||
SET "sender_public_id" = gen_random_uuid()
|
||||
WHERE "sender_public_id" IS NULL;
|
||||
ALTER TABLE "messages" ALTER COLUMN "sender_public_id" SET NOT NULL;
|
||||
|
||||
-- Outbox events already provide durable message event dedupe.
|
||||
CREATE INDEX "messages_conversation_seq_inbox_idx"
|
||||
ON "messages" ("conversation_id", "seq");
|
||||
CREATE INDEX "conversation_members_account_conversation_idx"
|
||||
ON "conversation_members" ("account_id", "conversation_id")
|
||||
WHERE "left_at" IS NULL;
|
||||
CREATE INDEX "conversations_last_message_cursor_idx"
|
||||
ON "conversations" ("last_message_at" DESC, "id" DESC);
|
||||
CREATE INDEX "sanctions_active_account_idx"
|
||||
ON "sanctions" ("account_id", "starts_at", "expires_at")
|
||||
WHERE "revoked_at" IS NULL;
|
||||
+17
-13
@@ -227,19 +227,19 @@ model Bottle {
|
||||
|
||||
model BottlePickLease {
|
||||
/// Partial unique index bottle_pick_leases_one_active_per_bottle is managed in 0001_init SQL.
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
bottleId String @map("bottle_id") @db.Uuid
|
||||
pickerId String @map("picker_id") @db.Uuid
|
||||
leaseTokenHash String @unique @map("lease_token_hash") @db.VarChar(255)
|
||||
leaseTokenCiphertext Bytes @map("lease_token_ciphertext")
|
||||
expiresAt DateTime @map("expires_at") @db.Timestamptz(3)
|
||||
status BottlePickLeaseStatus @default(ACTIVE)
|
||||
endedAt DateTime? @map("ended_at") @db.Timestamptz(3)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
bottle Bottle @relation(fields: [bottleId], references: [id], onDelete: Cascade)
|
||||
activeForBottle Bottle? @relation("ActiveBottleLease")
|
||||
picker Account @relation("PickerLeases", fields: [pickerId], references: [id], onDelete: Cascade)
|
||||
pickRequest BottlePickRequest?
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
bottleId String @map("bottle_id") @db.Uuid
|
||||
pickerId String @map("picker_id") @db.Uuid
|
||||
leaseTokenHash String @unique @map("lease_token_hash") @db.VarChar(255)
|
||||
leaseTokenCiphertext Bytes @map("lease_token_ciphertext")
|
||||
expiresAt DateTime @map("expires_at") @db.Timestamptz(3)
|
||||
status BottlePickLeaseStatus @default(ACTIVE)
|
||||
endedAt DateTime? @map("ended_at") @db.Timestamptz(3)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
bottle Bottle @relation(fields: [bottleId], references: [id], onDelete: Cascade)
|
||||
activeForBottle Bottle? @relation("ActiveBottleLease")
|
||||
picker Account @relation("PickerLeases", fields: [pickerId], references: [id], onDelete: Cascade)
|
||||
pickRequest BottlePickRequest?
|
||||
|
||||
@@index([pickerId, expiresAt])
|
||||
@@index([bottleId, expiresAt])
|
||||
@@ -304,10 +304,12 @@ model Conversation {
|
||||
reports Report[]
|
||||
|
||||
@@index([status, updatedAt])
|
||||
@@index([lastMessageAt(sort: Desc), id(sort: Desc)], map: "conversations_last_message_cursor_idx")
|
||||
@@map("conversations")
|
||||
}
|
||||
|
||||
model ConversationMember {
|
||||
/// Active member inbox index conversation_members_account_conversation_idx is managed in 0010 SQL.
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
conversationId String @map("conversation_id") @db.Uuid
|
||||
accountId String @map("account_id") @db.Uuid
|
||||
@@ -328,6 +330,7 @@ model Message {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
conversationId String @map("conversation_id") @db.Uuid
|
||||
senderId String @map("sender_id") @db.Uuid
|
||||
senderPublicId String @map("sender_public_id") @db.Uuid
|
||||
clientMsgId String @map("client_msg_id") @db.VarChar(128)
|
||||
seq BigInt
|
||||
contentText String @map("content_text") @db.Text
|
||||
@@ -343,6 +346,7 @@ model Message {
|
||||
|
||||
@@unique([conversationId, clientMsgId])
|
||||
@@unique([conversationId, seq])
|
||||
@@index([conversationId, seq], map: "messages_conversation_seq_inbox_idx")
|
||||
@@index([senderId, createdAt])
|
||||
@@map("messages")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user