fix: 为所有 ORM 模型添加外键约束及级联删除策略 #65

Merged
xiaoxia merged 14 commits from fix/database-foreign-key-constraints into main 2026-06-28 08:47:51 +08:00
Owner

变更内容

ORM 模型外键约束 (Task #17)

为所有 SQLAlchemy ORM 模型添加完整的 ForeignKey 约束和 relationship 定义:

  • 35 个外键约束:覆盖 16 张表的所有逻辑外键列
  • 级联删除策略:父子关系使用 ON DELETE CASCADE,可选用户引用使用 ON DELETE SET NULL
  • relationship 定义:所有模型添加 back_populates 双向关系,父侧配置 cascade=all,delete-orphan
  • 11 列 nullable 调整:SET NULL 策略的列从 nullable=False 改为 nullable=True
  • 2 个缺失索引:为 assets.uploaded_by_user_id 和 project_titles.created_by_user_id 添加索引

Pydantic 响应模型更新

将可能为 NULL 的响应字段从 str 改为 str | None,兼容 Pydantic v2

Alembic 迁移

新增 010_add_foreign_key_constraints.py,包含完整的 upgrade/downgrade

## 变更内容 ### ORM 模型外键约束 (Task #17) 为所有 SQLAlchemy ORM 模型添加完整的 ForeignKey 约束和 relationship 定义: - **35 个外键约束**:覆盖 16 张表的所有逻辑外键列 - **级联删除策略**:父子关系使用 ON DELETE CASCADE,可选用户引用使用 ON DELETE SET NULL - **relationship 定义**:所有模型添加 back_populates 双向关系,父侧配置 cascade=all,delete-orphan - **11 列 nullable 调整**:SET NULL 策略的列从 nullable=False 改为 nullable=True - **2 个缺失索引**:为 assets.uploaded_by_user_id 和 project_titles.created_by_user_id 添加索引 ### Pydantic 响应模型更新 将可能为 NULL 的响应字段从 str 改为 str | None,兼容 Pydantic v2 ### Alembic 迁移 新增 010_add_foreign_key_constraints.py,包含完整的 upgrade/downgrade
xiaoxia added 14 commits 2026-06-28 08:47:36 +08:00
fix: 修复 password_reset_use_case 循环导入问题
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
5b47d1adb7
fix: resolve circular import for password_hasher/password_validator in auth __init__
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
e1efbdaf6e
fix: correct import paths in domain/auth/__init__.py for jwt_service and password_hasher
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
06574c85a2
fix: correct all import paths for jwt_service and password_hasher (move from domain to application)
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
9d54b3e586
fix: swap parameter order in upload_asset to fix Python syntax error
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
8d4677ddee
fix: 清理前端 console.log/warn/error 调试日志
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
fb996a0a65
- 移除 ProjectGeneration.tsx 中唯一的 console.error 调用
- 确保生产构建不包含调试日志
- 前端代码中已无任何 console.log/warn/error

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
refactor: remove all workspace_id references from codebase
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
e3fb518ab2
- Remove workspace_id from Pydantic models in project_management routes
- Remove workspace_id from SQLAlchemy and SQLite project management repos
- Remove workspace_id from worker tasks (storage keys, entity creation)
- Remove workspace_id from video dedup and title usage modules
- Remove workspace_id from generation and ingest worker tasks
- Clean workspace_id from all test files and scripts
- Remove workspace-specific test files (list_workspaces, workspace repos)

Task: #14 workspace_id 残留清理
Merge pull request 'refactor: workspace_id 残留清理 - 移除所有 workspace_id 引用' (#62) from cleanup/workspace-id-removal into develop
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
2cd3cf03ff
feat(auth): implement refresh token mechanism
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
e90076f794
- Add /auth/refresh endpoint for token renewal
- Login response now includes refresh_token
- Update JWT defaults: access_token 15min, refresh_token 7days
- Reuse existing RefreshTokenUseCase with Redis session store
Merge pull request 'feat(auth): Refresh Token 机制实现' (#63) from feature/refresh-token-mechanism into develop
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
0f5b777043
Merge pull request 'fix: 清理前端 console.log/warn/error 调试日志' (#61) from fix/console-log-cleanup into develop
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
e10d65239e
feat(api): add Prometheus metrics middleware and /metrics endpoint
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
28733d6fc7
- Add prometheus-client==0.21.1 to requirements.txt
- Create PrometheusMetricsMiddleware to track HTTP request duration, count, and in-progress requests
- Add /metrics endpoint for Prometheus scraping
- Exclude health/ready/startup/metrics paths from recording to reduce noise
refactor: 统一 OSS 配置命名(MINIO_* → OSS_*)
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
e2c68888e9
- .env.production: MINIO_* 环境变量全部改为 OSS_* 命名
  - MINIO_ENDPOINT → OSS_ENDPOINT
  - MINIO_ACCESS_KEY → OSS_ACCESS_KEY_ID
  - MINIO_SECRET_KEY → OSS_ACCESS_KEY_SECRET
  - MINIO_BUCKET → OSS_BUCKET_NAME
  - MINIO_SECURE → OSS_SECURE
  - MINIO_PUBLIC_URL → OSS_PUBLIC_URL
- .env.staging: 修正 section header 为 OSS 对象存储配置
- storage.py: 移除 MinIOService 和 get_minio_service() 向后兼容别名
- test_architecture_boundaries.py: 移除 storage.py 的 allowed 例外
- 更新文档中的 MINIO_* 示例为 OSS_*:
  - docs/CI-CD.md
  - docs/基础设施安装指南.md
  - docs/本地验证检查清单.md
  - docs/静态验证报告-2026-06-19.md
fix: add foreign key constraints to all ORM models
Tests / test (pull_request) Failing after 0s
Tests / lint (pull_request) Failing after 0s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
01f5541e14
- Add 35 ForeignKey constraints across 15 tables (was zero)
- ON DELETE CASCADE for parent-child relationships (project → children)
- ON DELETE SET NULL for optional user references (created_by, assignee, etc.)
- Add relationship() with back_populates and cascade on all models
- Alter 11 columns from nullable=False to nullable=True for SET NULL
- Add 2 missing indexes on FK columns (assets.uploaded_by_user_id,
  project_titles.created_by_user_id)
- Update Pydantic response models to accept str | None for nullable fields
- Add Alembic migration 010 with complete upgrade/downgrade

Closes #17
xiaoxia merged commit 926d0fa272 into main 2026-06-28 08:47:51 +08:00
Sign in to join this conversation.