You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

6.0 KiB

2026-02-15 数据库 Models 和 Schemas 完整性检查

执行时间

2026-02-15 16:30

检查结果

数据库表完整性

数据库中的表数量: 44 个
Models 中定义的表数量: 44 个

✅ 所有 Models 定义的表都已在数据库中创建
✅ 数据库中的所有表都在 Models 中有定义
🎉 完美!Models 和数据库完全同步

⚠️ Schemas 缺失

发现 1 个 Model 缺少对应的 Schema:

1. ProjectResourceShare (project_resource_share.py)

Model 路径: server/app/models/project_resource_share.py
表名: project_resource_shares
状态: 缺少 Schema

Model 定义:

class ProjectResourceShare(SQLModel, table=True):
    """项目资源共享表(无物理外键,应用层校验)"""
    __tablename__ = "project_resource_shares"
    
    share_id: UUID
    source_project_id: UUID
    target_project_id: UUID
    share_type: int  # 1=整个项目, 2=特定资源类型, 3=特定资源
    resource_type: int | None  # 1=角色 2=场景 3=道具 4=素材
    resource_id: UUID | None
    status: int  # 1=ACTIVE, 2=DISCONNECTED
    created_at: datetime
    created_by: UUID
    updated_at: datetime

建议 Schema 结构:

# server/app/schemas/project_resource.py 或新建独立文件

class ProjectResourceShareCreate(BaseModel):
    """创建项目资源共享"""
    source_project_id: UUID
    target_project_id: UUID
    share_type: int  # 1=整个项目, 2=特定资源类型, 3=特定资源
    resource_type: int | None = None
    resource_id: UUID | None = None

class ProjectResourceShareUpdate(BaseModel):
    """更新项目资源共享"""
    status: int | None = None  # 1=ACTIVE, 2=DISCONNECTED

class ProjectResourceShareResponse(BaseModel):
    """项目资源共享响应"""
    share_id: UUID
    source_project_id: UUID
    target_project_id: UUID
    share_type: int
    resource_type: int | None
    resource_id: UUID | None
    status: int
    created_at: datetime
    created_by: UUID
    updated_at: datetime
    
    class Config:
        from_attributes = True

数据库表清单(44 个)

AI 相关(8 个)

  • ai_conversation_messages
  • ai_conversations
  • ai_jobs
  • ai_models
  • ai_prompts_system
  • ai_quotas
  • ai_skills_registry
  • ai_usage_logs

用户与认证(3 个)

  • users
  • user_sessions
  • sms_verification_codes

项目管理(8 个)

  • projects
  • project_members
  • project_shares
  • project_versions
  • project_resources
  • project_resource_shares ⚠️ 缺少 Schema
  • project_element_tags
  • project_characters
  • project_locations
  • project_props

剧本管理(3 个)

  • screenplays
  • screenplay_versions
  • screenplay_element_refs

分镜管理(8 个)

  • storyboards
  • storyboard_items
  • storyboard_images
  • storyboard_videos
  • storyboard_dialogues
  • storyboard_voiceovers
  • storyboard_sound_effects

文件夹管理(4 个)

  • folders
  • folder_members
  • folder_shares
  • folder_export_jobs

积分与支付(7 个)

  • credit_transactions
  • credit_consumption_logs
  • credit_packages
  • credit_pricing
  • credit_gifts
  • recharge_orders
  • payment_callbacks

其他(3 个)

  • attachments
  • file_checksums
  • alembic_version (系统表)

Models 与 Schemas 对应关系

有对应 Schema 的 Models(26 个)

Model 文件 Schema 文件 备注
ai_conversation.py ai_conversation.py
ai_conversation_message.py ai_conversation_message.py
ai_job.py ai.py 在 ai.py 中
ai_model.py ai.py 在 ai.py 中
ai_prompt_system.py ai_prompt_system.py
ai_quota.py ai.py 在 ai.py 中
ai_skill_registry.py ai_skill_registry.py
ai_usage_log.py ai.py 在 ai.py 中
attachment.py attachment.py
credit.py credit.py
file_checksum.py file_checksum.py
folder.py folder.py
project.py project.py
project_character.py project_element.py
project_element_tag.py project_element_tag.py
project_location.py project_element.py
project_prop.py project_element.py
project_resource.py project_resource.py
recharge/order.py recharge.py
screenplay.py screenplay.py
screenplay_element_ref.py screenplay_tag.py
screenplay_version.py screenplay.py
sms.py sms.py
storyboard.py storyboard.py
storyboard_resource.py storyboard_resource.py
storyboard_sound_effect.py storyboard_sound_effect.py
user.py user.py

缺少 Schema 的 Models(1 个)

Model 文件 表名 状态
project_resource_share.py project_resource_shares 需要创建

建议

立即处理

  1. 优先级:中 - 为 ProjectResourceShare 创建 Schema
    • 位置:server/app/schemas/project_resource.py(追加)或创建独立文件
    • 需要:Create、Update、Response 三个 Schema
    • 用途:项目间资源共享功能的 API 数据验证

可选优化

  1. 考虑是否需要为以下系统内部表创建 Schema(通常不需要):
    • file_checksums - 文件校验和(内部使用)
    • payment_callbacks - 支付回调记录(内部使用)
    • folder_export_jobs - 导出任务(可能需要查询接口)

总结

数据库迁移完整性: 100%(44/44 表全部创建)
⚠️ Schemas 完整性: 96.3%(26/27 有 Schema)
缺失 Schema: 1 个(project_resource_shares)

整体评估: 非常好!只有 1 个 Model 缺少 Schema,且该功能可能尚未实现 API 接口。


检查人: Claude (AI Assistant)
检查日期: 2026-02-15
数据库版本: cb015d9eec93 (head)
状态: 数据库健康,⚠️ 1 个 Schema 待补充