fix(db): drop files_user_id_fkey — anonymous users may not exist in users table

The conversations table has no FK on user_id, but files had one, causing
500 errors on file upload when the anonymous user wasn't registered.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-07 08:11:37 -08:00
parent 308dd7798e
commit 06226a3d74
2 changed files with 4 additions and 1 deletions

View File

@ -1604,7 +1604,7 @@ CREATE TABLE files (
-- 租户ID -- 租户ID
tenant_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001', tenant_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001',
-- 所属用户ID -- 所属用户ID
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, user_id UUID NOT NULL,
-- 关联的对话ID可选 -- 关联的对话ID可选
conversation_id UUID REFERENCES conversations(id) ON DELETE SET NULL, conversation_id UUID REFERENCES conversations(id) ON DELETE SET NULL,
-- 原始文件名 -- 原始文件名

View File

@ -0,0 +1,3 @@
-- Drop foreign key constraint on files.user_id
-- Anonymous users may not exist in users table (conversations also has no FK on user_id)
ALTER TABLE files DROP CONSTRAINT IF EXISTS files_user_id_fkey;