fix: expand all UUID fields from varchar(32) to varchar(36) [P0] #204
@@ -0,0 +1,68 @@
|
||||
"""Expand UUID fields from varchar(32) to varchar(36)
|
||||
|
||||
All UUID fields across all tables were varchar(32), but standard UUIDs with
|
||||
hyphens are 36 characters (e.g. 550e8400-e29b-41d4-a716-446655440000).
|
||||
This caused StringDataRightTruncation errors on insert.
|
||||
|
||||
Revision ID: 036_expand_uuid_36
|
||||
Revises: 035_editing_mode
|
||||
Create Date: 2026-07-10
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = "036_expand_uuid_36"
|
||||
down_revision = "035_editing_mode"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
# ── 表 → 需要扩容的列 ─────────────────────────────────────────────────────────
|
||||
|
||||
_TABLES: dict[str, list[str]] = {
|
||||
"projects": ["id", "owner_user_id"],
|
||||
"edit_templates": ["id"],
|
||||
"edit_plans": ["id", "template_id", "source_edit_plan_id", "project_id", "created_by_user_id"],
|
||||
"template_clip_configs": ["id", "template_id"],
|
||||
"edit_plan_clips": ["id", "plan_id", "template_clip_config_id", "asset_id"],
|
||||
"ingest_jobs": ["id", "project_id", "library_id", "result_asset_id"],
|
||||
"classification_jobs": ["id", "project_id", "asset_id"],
|
||||
"generation_tasks": [
|
||||
"id",
|
||||
"project_id",
|
||||
"strategy_id",
|
||||
"asset_library_id",
|
||||
"voice_library_id",
|
||||
"created_by_user_id",
|
||||
"source_edit_plan_id",
|
||||
"batch_id",
|
||||
],
|
||||
"generated_videos": ["id", "project_id", "generation_task_id", "duplicate_of"],
|
||||
"jobs": ["id", "project_id", "source_id", "created_by_user_id"],
|
||||
}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
for table, columns in _TABLES.items():
|
||||
for col in columns:
|
||||
op.alter_column(
|
||||
table,
|
||||
col,
|
||||
existing_type=sa.String(32),
|
||||
type_=sa.String(36),
|
||||
existing_nullable=None,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
for table, columns in reversed(list(_TABLES.items())):
|
||||
for col in columns:
|
||||
op.alter_column(
|
||||
table,
|
||||
col,
|
||||
existing_type=sa.String(36),
|
||||
type_=sa.String(32),
|
||||
existing_nullable=None,
|
||||
)
|
||||
@@ -473,7 +473,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -481,7 +481,7 @@
|
||||
"name": "project_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -489,7 +489,7 @@
|
||||
"name": "asset_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -783,7 +783,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -791,7 +791,7 @@
|
||||
"name": "plan_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -815,7 +815,7 @@
|
||||
"name": "template_clip_config_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -823,7 +823,7 @@
|
||||
"name": "asset_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -939,7 +939,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -947,7 +947,7 @@
|
||||
"name": "template_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -987,7 +987,7 @@
|
||||
"name": "source_edit_plan_id",
|
||||
"nullable": true,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -995,7 +995,7 @@
|
||||
"name": "project_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1003,7 +1003,7 @@
|
||||
"name": "created_by_user_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1071,7 +1071,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1189,7 +1189,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1197,7 +1197,7 @@
|
||||
"name": "project_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1205,7 +1205,7 @@
|
||||
"name": "generation_task_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1341,7 +1341,7 @@
|
||||
"name": "duplicate_of",
|
||||
"nullable": true,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
}
|
||||
],
|
||||
@@ -1386,7 +1386,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1394,7 +1394,7 @@
|
||||
"name": "project_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1402,7 +1402,7 @@
|
||||
"name": "strategy_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1410,7 +1410,7 @@
|
||||
"name": "asset_library_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1418,7 +1418,7 @@
|
||||
"name": "voice_library_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1514,7 +1514,7 @@
|
||||
"name": "created_by_user_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1522,7 +1522,7 @@
|
||||
"name": "source_edit_plan_id",
|
||||
"nullable": true,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1538,7 +1538,7 @@
|
||||
"name": "batch_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1627,7 +1627,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1635,7 +1635,7 @@
|
||||
"name": "project_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1643,7 +1643,7 @@
|
||||
"name": "library_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1675,7 +1675,7 @@
|
||||
"name": "result_asset_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1737,7 +1737,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1745,7 +1745,7 @@
|
||||
"name": "project_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1833,7 +1833,7 @@
|
||||
"name": "source_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1841,7 +1841,7 @@
|
||||
"name": "created_by_user_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1925,7 +1925,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -1933,7 +1933,7 @@
|
||||
"name": "owner_user_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -2253,7 +2253,7 @@
|
||||
"name": "id",
|
||||
"nullable": false,
|
||||
"primary_key": true,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
@@ -2261,7 +2261,7 @@
|
||||
"name": "template_id",
|
||||
"nullable": false,
|
||||
"primary_key": false,
|
||||
"type": "VARCHAR(32)",
|
||||
"type": "VARCHAR(36)",
|
||||
"unique": false
|
||||
},
|
||||
{
|
||||
|
||||
@@ -39,8 +39,8 @@ class UserModel(Base):
|
||||
class ProjectModel(Base):
|
||||
__tablename__ = "projects"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
owner_user_id = Column(String(32), nullable=False, index=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
owner_user_id = Column(String(36), nullable=False, index=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
description = Column(Text, nullable=False, default="")
|
||||
shared_users = Column(JSON, nullable=False, default=list) # 被共享的用户 ID 列表
|
||||
@@ -122,7 +122,7 @@ class EditTemplateModel(Base):
|
||||
|
||||
__tablename__ = "edit_templates"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
name = Column(String(120), nullable=False)
|
||||
description = Column(Text, nullable=False, default="")
|
||||
template_type = Column(String(50), nullable=False, default="default", index=True)
|
||||
@@ -143,15 +143,15 @@ class EditPlanModel(Base):
|
||||
|
||||
__tablename__ = "edit_plans"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
template_id = Column(String(32), nullable=False, index=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
template_id = Column(String(36), nullable=False, index=True)
|
||||
name = Column(String(200), nullable=False)
|
||||
status = Column(String(20), nullable=False, default="draft", index=True)
|
||||
total_duration = Column(Float, nullable=False, default=0.0)
|
||||
config = Column(JSON, nullable=False, default=dict)
|
||||
source_edit_plan_id = Column(String(32), nullable=True, index=True)
|
||||
project_id = Column(String(32), nullable=False, default="", index=True)
|
||||
created_by_user_id = Column(String(32), nullable=False, default="", index=True)
|
||||
source_edit_plan_id = Column(String(36), nullable=True, index=True)
|
||||
project_id = Column(String(36), nullable=False, default="", index=True)
|
||||
created_by_user_id = Column(String(36), nullable=False, default="", index=True)
|
||||
created_at = Column(DateTime, nullable=False, default=lambda: datetime.now(timezone.utc))
|
||||
updated_at = Column(DateTime, nullable=False, default=lambda: datetime.now(timezone.utc))
|
||||
|
||||
@@ -164,8 +164,8 @@ class TemplateClipConfigModel(Base):
|
||||
|
||||
__tablename__ = "template_clip_configs"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
template_id = Column(String(32), nullable=False, index=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
template_id = Column(String(36), nullable=False, index=True)
|
||||
clip_type = Column(String(20), nullable=False, index=True)
|
||||
order = Column(Integer, nullable=False)
|
||||
min_duration = Column(Float, nullable=False, default=0.0)
|
||||
@@ -186,12 +186,12 @@ class EditPlanClipModel(Base):
|
||||
|
||||
__tablename__ = "edit_plan_clips"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
plan_id = Column(String(32), nullable=False, index=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
plan_id = Column(String(36), nullable=False, index=True)
|
||||
clip_type = Column(String(20), nullable=False, index=True)
|
||||
order = Column(Integer, nullable=False)
|
||||
template_clip_config_id = Column(String(32), nullable=False, default="", index=True)
|
||||
asset_id = Column(String(32), nullable=False, default="", index=True)
|
||||
template_clip_config_id = Column(String(36), nullable=False, default="", index=True)
|
||||
asset_id = Column(String(36), nullable=False, default="", index=True)
|
||||
text_content = Column(Text, nullable=False, default="")
|
||||
start_time = Column(Float, nullable=False, default=0.0)
|
||||
duration = Column(Float, nullable=False, default=0.0)
|
||||
@@ -205,13 +205,13 @@ class EditPlanClipModel(Base):
|
||||
class IngestJobModel(Base):
|
||||
__tablename__ = "ingest_jobs"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
project_id = Column(String(32), nullable=False, index=True)
|
||||
library_id = Column(String(32), nullable=False, index=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
project_id = Column(String(36), nullable=False, index=True)
|
||||
library_id = Column(String(36), nullable=False, index=True)
|
||||
storage_key = Column(String(255), nullable=False)
|
||||
status = Column(String(20), nullable=False, default="pending")
|
||||
error_message = Column(Text, nullable=False, default="")
|
||||
result_asset_id = Column(String(32), nullable=False, default="")
|
||||
result_asset_id = Column(String(36), nullable=False, default="")
|
||||
file_hash = Column(String(64), nullable=True, index=True)
|
||||
created_at = Column(DateTime, nullable=False, default=lambda: datetime.now(timezone.utc))
|
||||
updated_at = Column(DateTime, nullable=False, default=lambda: datetime.now(timezone.utc))
|
||||
@@ -220,9 +220,9 @@ class IngestJobModel(Base):
|
||||
class ClassificationJobModel(Base):
|
||||
__tablename__ = "classification_jobs"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
project_id = Column(String(32), nullable=False, index=True)
|
||||
asset_id = Column(String(32), nullable=False, index=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
project_id = Column(String(36), nullable=False, index=True)
|
||||
asset_id = Column(String(36), nullable=False, index=True)
|
||||
status = Column(String(20), nullable=False, default="pending")
|
||||
classification = Column(String(50), nullable=False, default="")
|
||||
confidence = Column(Float, nullable=False, default=0.0)
|
||||
@@ -234,11 +234,11 @@ class ClassificationJobModel(Base):
|
||||
class GenerationTaskModel(Base):
|
||||
__tablename__ = "generation_tasks"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
project_id = Column(String(32), nullable=False, default="", index=True)
|
||||
strategy_id = Column(String(32), nullable=False, default="")
|
||||
asset_library_id = Column(String(32), nullable=False, default="", index=True)
|
||||
voice_library_id = Column(String(32), nullable=False, default="")
|
||||
id = Column(String(36), primary_key=True)
|
||||
project_id = Column(String(36), nullable=False, default="", index=True)
|
||||
strategy_id = Column(String(36), nullable=False, default="")
|
||||
asset_library_id = Column(String(36), nullable=False, default="", index=True)
|
||||
voice_library_id = Column(String(36), nullable=False, default="")
|
||||
template_id = Column(String(36), nullable=False, default="", index=True)
|
||||
asset_ids = Column(JSON, nullable=False, default=list)
|
||||
title_ids = Column(JSON, nullable=False, default=list)
|
||||
@@ -252,10 +252,10 @@ class GenerationTaskModel(Base):
|
||||
error_message = Column(Text, nullable=False, default="")
|
||||
started_at = Column(DateTime, nullable=True)
|
||||
completed_at = Column(DateTime, nullable=True)
|
||||
created_by_user_id = Column(String(32), nullable=False, default="", index=True)
|
||||
source_edit_plan_id = Column(String(32), nullable=True, index=True)
|
||||
created_by_user_id = Column(String(36), nullable=False, default="", index=True)
|
||||
source_edit_plan_id = Column(String(36), nullable=True, index=True)
|
||||
asset_select_mode = Column(String(20), nullable=False, default="")
|
||||
batch_id = Column(String(32), nullable=False, default="", index=True)
|
||||
batch_id = Column(String(36), nullable=False, default="", index=True)
|
||||
extra_meta = Column("metadata", JSON, nullable=False, default=dict)
|
||||
created_at = Column(DateTime, nullable=False, default=lambda: datetime.now(timezone.utc))
|
||||
|
||||
@@ -263,9 +263,9 @@ class GenerationTaskModel(Base):
|
||||
class GeneratedVideoModel(Base):
|
||||
__tablename__ = "generated_videos"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
project_id = Column(String(32), nullable=False, index=True)
|
||||
generation_task_id = Column(String(32), nullable=False, index=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
project_id = Column(String(36), nullable=False, index=True)
|
||||
generation_task_id = Column(String(36), nullable=False, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
# file_url: 完整可访问的 URL,用于客户端直接访问视频
|
||||
file_url = Column(String(1000), nullable=False)
|
||||
@@ -284,7 +284,7 @@ class GeneratedVideoModel(Base):
|
||||
updated_at = Column(DateTime, nullable=True)
|
||||
video_fingerprint = Column(Text, nullable=True)
|
||||
is_duplicate = Column(Boolean, nullable=False, default=False)
|
||||
duplicate_of = Column(String(32), nullable=True)
|
||||
duplicate_of = Column(String(36), nullable=True)
|
||||
|
||||
|
||||
class TitleLibraryModel(Base):
|
||||
@@ -451,8 +451,8 @@ class JobModel(Base):
|
||||
|
||||
__tablename__ = "jobs"
|
||||
|
||||
id = Column(String(32), primary_key=True)
|
||||
project_id = Column(String(32), nullable=False, index=True)
|
||||
id = Column(String(36), primary_key=True)
|
||||
project_id = Column(String(36), nullable=False, index=True)
|
||||
job_type = Column(String(30), nullable=False, index=True)
|
||||
status = Column(String(20), nullable=False, default="pending", index=True)
|
||||
progress = Column(Float, nullable=False, default=0.0)
|
||||
@@ -463,8 +463,8 @@ class JobModel(Base):
|
||||
retry_count = Column(Integer, nullable=False, default=0)
|
||||
max_retries = Column(Integer, nullable=False, default=3)
|
||||
celery_task_id = Column(String(100), nullable=False, default="")
|
||||
source_id = Column(String(32), nullable=False, default="", index=True)
|
||||
created_by_user_id = Column(String(32), nullable=False, default="", index=True)
|
||||
source_id = Column(String(36), nullable=False, default="", index=True)
|
||||
created_by_user_id = Column(String(36), nullable=False, default="", index=True)
|
||||
started_at = Column(DateTime, nullable=True)
|
||||
completed_at = Column(DateTime, nullable=True)
|
||||
created_at = Column(DateTime, nullable=False, default=lambda: datetime.now(timezone.utc))
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
"""UUID 字段长度单元测试 — 验证标准 UUID(带横杠,36字符)可正常插入.
|
||||
|
||||
覆盖:
|
||||
- 所有从 varchar(32) 扩到 varchar(36) 的表
|
||||
- 插入标准 UUID 格式(带横杠)不报 StringDataRightTruncation
|
||||
- 字段长度从 32 扩到 36 后 ORM 模型定义正确
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from packages.adapters.sqlalchemy_impl.models import (
|
||||
Base,
|
||||
ClassificationJobModel,
|
||||
EditPlanClipModel,
|
||||
EditPlanModel,
|
||||
EditTemplateModel,
|
||||
GeneratedVideoModel,
|
||||
GenerationTaskModel,
|
||||
IngestJobModel,
|
||||
JobModel,
|
||||
ProjectModel,
|
||||
TemplateClipConfigModel,
|
||||
)
|
||||
|
||||
|
||||
def _uuid() -> str:
|
||||
"""生成标准 UUID 字符串(带横杠,36 字符)."""
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
class TestUUIDFieldLengthModels:
|
||||
"""验证 ORM 模型中 UUID 字段定义为 String(36)."""
|
||||
|
||||
def _get_column_type_length(self, model_cls, column_name: str) -> int:
|
||||
"""获取模型列的 String 长度."""
|
||||
col = model_cls.__table__.columns[column_name]
|
||||
return col.type.length
|
||||
|
||||
# ── ProjectModel ──────────────────────────────────────────────────────────
|
||||
|
||||
def test_project_id_is_36(self):
|
||||
assert self._get_column_type_length(ProjectModel, "id") == 36
|
||||
|
||||
def test_project_owner_user_id_is_36(self):
|
||||
assert self._get_column_type_length(ProjectModel, "owner_user_id") == 36
|
||||
|
||||
# ── EditTemplateModel ─────────────────────────────────────────────────────
|
||||
|
||||
def test_edit_template_id_is_36(self):
|
||||
assert self._get_column_type_length(EditTemplateModel, "id") == 36
|
||||
|
||||
# ── EditPlanModel ─────────────────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"col",
|
||||
["id", "template_id", "source_edit_plan_id", "project_id", "created_by_user_id"],
|
||||
)
|
||||
def test_edit_plan_uuid_fields_are_36(self, col):
|
||||
assert self._get_column_type_length(EditPlanModel, col) == 36
|
||||
|
||||
# ── TemplateClipConfigModel ───────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.parametrize("col", ["id", "template_id"])
|
||||
def test_template_clip_config_uuid_fields_are_36(self, col):
|
||||
assert self._get_column_type_length(TemplateClipConfigModel, col) == 36
|
||||
|
||||
# ── EditPlanClipModel ─────────────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"col",
|
||||
["id", "plan_id", "template_clip_config_id", "asset_id"],
|
||||
)
|
||||
def test_edit_plan_clip_uuid_fields_are_36(self, col):
|
||||
assert self._get_column_type_length(EditPlanClipModel, col) == 36
|
||||
|
||||
# ── IngestJobModel(P0 bug 所在表)─────────────────────────────────────────
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"col",
|
||||
["id", "project_id", "library_id", "result_asset_id"],
|
||||
)
|
||||
def test_ingest_job_uuid_fields_are_36(self, col):
|
||||
assert self._get_column_type_length(IngestJobModel, col) == 36
|
||||
|
||||
def test_ingest_job_library_id_accepts_standard_uuid(self):
|
||||
"""P0 回归:library_id 必须能容纳标准 UUID(36 字符带横杠)."""
|
||||
standard_uuid = "550e8400-e29b-41d4-a716-446655440000"
|
||||
assert len(standard_uuid) == 36
|
||||
col = IngestJobModel.__table__.columns["library_id"]
|
||||
assert col.type.length >= 36
|
||||
|
||||
# ── ClassificationJobModel ────────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.parametrize("col", ["id", "project_id", "asset_id"])
|
||||
def test_classification_job_uuid_fields_are_36(self, col):
|
||||
assert self._get_column_type_length(ClassificationJobModel, col) == 36
|
||||
|
||||
# ── GenerationTaskModel ───────────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"col",
|
||||
[
|
||||
"id",
|
||||
"project_id",
|
||||
"strategy_id",
|
||||
"asset_library_id",
|
||||
"voice_library_id",
|
||||
"created_by_user_id",
|
||||
"source_edit_plan_id",
|
||||
"batch_id",
|
||||
],
|
||||
)
|
||||
def test_generation_task_uuid_fields_are_36(self, col):
|
||||
assert self._get_column_type_length(GenerationTaskModel, col) == 36
|
||||
|
||||
# ── GeneratedVideoModel ───────────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"col",
|
||||
["id", "project_id", "generation_task_id", "duplicate_of"],
|
||||
)
|
||||
def test_generated_video_uuid_fields_are_36(self, col):
|
||||
assert self._get_column_type_length(GeneratedVideoModel, col) == 36
|
||||
|
||||
# ── JobModel ──────────────────────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"col",
|
||||
["id", "project_id", "source_id", "created_by_user_id"],
|
||||
)
|
||||
def test_job_uuid_fields_are_36(self, col):
|
||||
assert self._get_column_type_length(JobModel, col) == 36
|
||||
|
||||
|
||||
class TestUUIDInsertWithHyphens:
|
||||
"""验证标准 UUID(带横杠)可构造 ORM 对象,字段长度足够."""
|
||||
|
||||
def test_ingest_job_model_construct_with_standard_uuid(self):
|
||||
"""P0 回归测试:用标准 UUID 构造 IngestJobModel 不报错."""
|
||||
std_uuid = _uuid()
|
||||
assert len(std_uuid) == 36
|
||||
|
||||
job = IngestJobModel(
|
||||
id=_uuid(),
|
||||
project_id=_uuid(),
|
||||
library_id=std_uuid, # ← 关键:标准 UUID 带横杠
|
||||
storage_key="test/file.mp4",
|
||||
result_asset_id=_uuid(),
|
||||
)
|
||||
assert job.library_id == std_uuid
|
||||
assert len(job.library_id) == 36
|
||||
|
||||
def test_project_model_construct_with_standard_uuid(self):
|
||||
project = ProjectModel(
|
||||
id=_uuid(),
|
||||
owner_user_id=_uuid(),
|
||||
name="test",
|
||||
)
|
||||
assert len(project.id) == 36
|
||||
assert len(project.owner_user_id) == 36
|
||||
|
||||
def test_generation_task_model_construct_with_standard_uuid(self):
|
||||
task = GenerationTaskModel(
|
||||
id=_uuid(),
|
||||
project_id=_uuid(),
|
||||
asset_library_id=_uuid(),
|
||||
created_by_user_id=_uuid(),
|
||||
source_edit_plan_id=_uuid(),
|
||||
batch_id=_uuid(),
|
||||
)
|
||||
assert len(task.id) == 36
|
||||
assert len(task.asset_library_id) == 36
|
||||
|
||||
def test_edit_plan_model_construct_with_standard_uuid(self):
|
||||
plan = EditPlanModel(
|
||||
id=_uuid(),
|
||||
template_id=_uuid(),
|
||||
source_edit_plan_id=_uuid(),
|
||||
project_id=_uuid(),
|
||||
created_by_user_id=_uuid(),
|
||||
)
|
||||
assert len(plan.id) == 36
|
||||
assert len(plan.template_id) == 36
|
||||
|
||||
def test_generated_video_model_construct_with_standard_uuid(self):
|
||||
video = GeneratedVideoModel(
|
||||
id=_uuid(),
|
||||
project_id=_uuid(),
|
||||
generation_task_id=_uuid(),
|
||||
duplicate_of=_uuid(),
|
||||
name="test.mp4",
|
||||
file_url="https://example.com/test.mp4",
|
||||
file_size=1000,
|
||||
duration=10.0,
|
||||
width=1280,
|
||||
height=720,
|
||||
fps=25.0,
|
||||
)
|
||||
assert len(video.id) == 36
|
||||
assert len(video.duplicate_of) == 36
|
||||
Reference in New Issue
Block a user