ai_video.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """
  2. AI视频生成ORM定义
  3. 定义AI视频生成系统的数据库表结构
  4. """
  5. from datetime import datetime
  6. from sqlalchemy import Column, Integer, String, Text, DateTime, Numeric, Boolean, Index
  7. from sqlalchemy.dialects.postgresql import JSONB
  8. from sqlalchemy.sql import func
  9. from app.database import Base
  10. class VideoModelConfig(Base):
  11. """视频模型参数配置表"""
  12. __tablename__ = "video_model_config"
  13. id = Column(Integer, primary_key=True, autoincrement=True)
  14. model_name = Column(String(100), unique=True, nullable=False, comment="模型名称")
  15. model_id = Column(String(100), nullable=False, comment="模型ID")
  16. model_type = Column(String(50), nullable=False, comment="模型类型:t2v/i2v/s2v")
  17. supported_params = Column(JSONB, nullable=False, comment="支持的参数配置JSON")
  18. is_active = Column(Boolean, default=True, comment="是否启用")
  19. created_at = Column(DateTime, server_default=func.now())
  20. updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
  21. __table_args__ = (
  22. Index('idx_video_model_config_type', 'model_type'),
  23. Index('idx_video_model_config_active', 'is_active'),
  24. {'schema': 'aigcspace', 'comment': '视频模型参数配置表'}
  25. )
  26. class AIVideo(Base):
  27. """AI视频生成记录表"""
  28. __tablename__ = "ai_video"
  29. id = Column(Integer, primary_key=True, autoincrement=True)
  30. user_id = Column(String(100), nullable=False, comment="用户ID")
  31. task_id = Column(String(100), unique=True, nullable=False, comment="百炼平台任务ID")
  32. model_name = Column(String(100), nullable=False, comment="使用的模型名称")
  33. video_type = Column(String(50), nullable=False, comment="视频类型:t2v/i2v/s2v")
  34. input_params = Column(JSONB, nullable=False, comment="输入参数JSON")
  35. prompt = Column(Text, comment="原始提示词")
  36. actual_prompt = Column(Text, comment="智能改写后的提示词")
  37. first_frame_url = Column(String(500), comment="首帧图片URL")
  38. last_frame_url = Column(String(500), comment="尾帧图片URL")
  39. audio_url = Column(String(500), comment="音频URL")
  40. video_url = Column(String(500), comment="输出视频OSS URL")
  41. video_duration = Column(Numeric(10, 2), comment="视频时长(秒)")
  42. resolution = Column(String(20), comment="视频分辨率")
  43. custom_name = Column(String(200), comment="用户自定义名称")
  44. status = Column(String(20), nullable=False, default='PENDING', comment="任务状态")
  45. error_message = Column(Text, comment="错误信息")
  46. bill = Column(Numeric(10, 4), default=0, comment="任务消耗费用")
  47. # 审核状态
  48. review_status = Column(String(20), default="pending", comment="审核状态")
  49. reviewed_by = Column(Integer, comment="审核人ID")
  50. reviewed_at = Column(DateTime, comment="审核时间")
  51. reject_reason = Column(String(500), comment="拒绝原因")
  52. submit_time = Column(DateTime, comment="任务提交时间")
  53. scheduled_time = Column(DateTime, comment="任务开始执行时间")
  54. end_time = Column(DateTime, comment="任务完成时间")
  55. created_at = Column(DateTime, server_default=func.now())
  56. updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
  57. __table_args__ = (
  58. Index('idx_ai_video_user_id', 'user_id'),
  59. Index('idx_ai_video_task_id', 'task_id'),
  60. Index('idx_ai_video_status', 'status'),
  61. Index('idx_ai_video_created_at', 'created_at'),
  62. Index('idx_ai_video_video_type', 'video_type'),
  63. {'schema': 'aigcspace', 'comment': 'AI视频生成记录表'}
  64. )