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? name String?
createdBy User @relation(fields: [createdById], references: [id], onDelete: Cascade) createdBy User? @relation(fields: [createdById], references: [id], onDelete: Cascade)
createdById String createdById String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt

View file

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