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:
2026-06-05 01:02:23 +08:00
parent e25b2537fd
commit db40d04dc5
37 changed files with 1564 additions and 324 deletions

View File

@@ -6,7 +6,7 @@ export interface ApiErrorResponse {
export interface Conversation {
createdAt: string;
id: string;
modelId: string;
modelId: null | string;
projectId: string;
title: string;
updatedAt: string;
@@ -36,8 +36,8 @@ export interface CreateMaterialRequest {
export interface CreateModelRequest {
capabilities: ModelCapability[];
contextLength?: null | number;
externalId: string;
maxOutputTokens?: null | number;
modelId: string;
name: string;
providerId: string;
}
@@ -94,6 +94,7 @@ export interface Message {
id: string;
parts: null | string;
role: "assistant" | "system" | "user";
updatedAt: string;
}
export interface MessageListResponse {
@@ -114,9 +115,9 @@ export interface Model {
capabilities: ModelCapability[];
contextLength: null | number;
createdAt: string;
externalId: string;
id: string;
maxOutputTokens: null | number;
modelId: string;
name: string;
providerId: string;
updatedAt: string;
@@ -171,7 +172,6 @@ export interface ModelTestResultResponse {
}
export interface Project {
archivedAt: null | string;
createdAt: string;
description: string;
id: string;
@@ -238,15 +238,15 @@ export type ProviderType = "anthropic" | "openai" | "openai-compatible";
export type RuntimeMode = "development" | "production" | "test";
export interface TestModelRequest {
modelId: string;
externalId: string;
providerId: string;
}
export interface UpdateModelRequest {
capabilities?: ModelCapability[];
contextLength?: null | number;
externalId?: string;
maxOutputTokens?: null | number;
modelId?: string;
name?: string;
providerId?: string;
}