refactor(db): 统一数据库 schema — 软删除、命名规范、约束标准化
- 全表新增 deleted_at 列,统一软删除替代硬删除+archived_at - models.model_id 重命名为 external_id,消除语义混淆 - conversations.model_id 改为可空(模型为建议而非绑定) - messages 新增 updated_at,移除 CASCADE 改为 DAO 层级联 - 移除 DB 层 UNIQUE 约束,改为应用层检查(配合软删除) - 新增 helpers.ts(baseColumns + 构造层防御)、ESLint 规则、契约测试 - 迁移 0004 补全 CHECK 约束(providers.type/materials.status/messages.role) - DAO 层全面重写:级联软删除、应用层唯一、provider 删除保护 - 路由/前端/测试全量适配 externalId 重命名及类型变更
This commit is contained in:
@@ -44,12 +44,12 @@ async function patchConversationViaHandler(req: Request, db: Database): Promise<
|
||||
return h(req, db, MODE, LOG);
|
||||
}
|
||||
|
||||
function seedModel(db: Database, providerId: string, modelName = "GPT-4o", modelId = "gpt-4o"): string {
|
||||
function seedModel(db: Database, providerId: string, modelName = "GPT-4o", externalId = "gpt-4o"): string {
|
||||
const result = createModel(
|
||||
db,
|
||||
{
|
||||
capabilities: ["text"],
|
||||
modelId,
|
||||
externalId,
|
||||
name: modelName,
|
||||
providerId,
|
||||
},
|
||||
@@ -111,7 +111,7 @@ describe("聊天 API 路由", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("无可用模型时返回 400", async () => {
|
||||
test("无可用模型时创建会话 modelId 为 null", async () => {
|
||||
const handle = createMigratedMemoryTestDatabase("chat-create-no-model");
|
||||
try {
|
||||
const db = handle.db;
|
||||
@@ -123,9 +123,9 @@ describe("聊天 API 路由", () => {
|
||||
method: "POST",
|
||||
});
|
||||
const res = await createConversationViaHandler(req, db);
|
||||
expect(res.status).toBe(400);
|
||||
const body = (await res.json()) as { error: string };
|
||||
expect(body.error).toContain("模型");
|
||||
expect(res.status).toBe(201);
|
||||
const body = (await res.json()) as { conversation: Conversation };
|
||||
expect(body.conversation.modelId).toBeNull();
|
||||
handle.close();
|
||||
} finally {
|
||||
handle.cleanup();
|
||||
|
||||
Reference in New Issue
Block a user