This commit is contained in:
bkellam 2025-11-28 22:38:11 -08:00
parent f1dd16be82
commit 3d88505257
3 changed files with 9 additions and 5 deletions

View file

@ -0,0 +1,5 @@
-- Set all chats created by the guest user (id: 1) to have a NULL createdById.
UPDATE "Chat" SET "createdById" = NULL WHERE "createdById" = '1';
-- AlterTable
ALTER TABLE "Chat" ALTER COLUMN "createdById" DROP NOT NULL;

View file

@ -437,8 +437,8 @@ model Chat {
name String?
createdBy User @relation(fields: [createdById], references: [id], onDelete: Cascade)
createdById String
createdBy User? @relation(fields: [createdById], references: [id], onDelete: Cascade)
createdById String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

View file

@ -1,7 +1,6 @@
'use server';
import { sew } from "@/actions";
import { SOURCEBOT_GUEST_USER_ID } from "@/lib/constants";
import { ErrorCode } from "@/lib/errorCodes";
import { chatIsReadonly, notFound, ServiceError, serviceErrorResponse } from "@/lib/serviceError";
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
@ -34,13 +33,13 @@ const logger = createLogger('chat-actions');
export const createChat = async () => sew(() =>
withOptionalAuthV2(async ({ org, user, prisma }) => {
const isGuestUser = user?.id === SOURCEBOT_GUEST_USER_ID;
const isGuestUser = user === undefined;
const chat = await prisma.chat.create({
data: {
orgId: org.id,
messages: [] as unknown as Prisma.InputJsonValue,
createdById: user?.id ?? SOURCEBOT_GUEST_USER_ID,
createdById: user?.id,
visibility: isGuestUser ? ChatVisibility.PUBLIC : ChatVisibility.PRIVATE,
},
});