Skip to content

Commit 3d88505

Browse files
fix
1 parent f1dd16b commit 3d88505

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Set all chats created by the guest user (id: 1) to have a NULL createdById.
2+
UPDATE "Chat" SET "createdById" = NULL WHERE "createdById" = '1';
3+
4+
-- AlterTable
5+
ALTER TABLE "Chat" ALTER COLUMN "createdById" DROP NOT NULL;

packages/db/prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ model Chat {
437437
438438
name String?
439439
440-
createdBy User @relation(fields: [createdById], references: [id], onDelete: Cascade)
441-
createdById String
440+
createdBy User? @relation(fields: [createdById], references: [id], onDelete: Cascade)
441+
createdById String?
442442
443443
createdAt DateTime @default(now())
444444
updatedAt DateTime @updatedAt

packages/web/src/features/chat/actions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use server';
22

33
import { sew } from "@/actions";
4-
import { SOURCEBOT_GUEST_USER_ID } from "@/lib/constants";
54
import { ErrorCode } from "@/lib/errorCodes";
65
import { chatIsReadonly, notFound, ServiceError, serviceErrorResponse } from "@/lib/serviceError";
76
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
@@ -34,13 +33,13 @@ const logger = createLogger('chat-actions');
3433

3534
export const createChat = async () => sew(() =>
3635
withOptionalAuthV2(async ({ org, user, prisma }) => {
37-
const isGuestUser = user?.id === SOURCEBOT_GUEST_USER_ID;
36+
const isGuestUser = user === undefined;
3837

3938
const chat = await prisma.chat.create({
4039
data: {
4140
orgId: org.id,
4241
messages: [] as unknown as Prisma.InputJsonValue,
43-
createdById: user?.id ?? SOURCEBOT_GUEST_USER_ID,
42+
createdById: user?.id,
4443
visibility: isGuestUser ? ChatVisibility.PUBLIC : ChatVisibility.PRIVATE,
4544
},
4645
});

0 commit comments

Comments
 (0)