"""add avatars table Revision ID: d4bd9ad91607 Revises: fb1be66e804a Create Date: 2026-04-06 21:51:36.225361 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = 'd4bd9ad91607' down_revision: Union[str, Sequence[str], None] = 'fb1be66e804a' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: """Upgrade schema.""" # ### commands auto generated by Alembic - please adjust! ### op.create_table('avatars', sa.Column('id', sa.String(length=64), nullable=False, comment='形象唯一标识(Kling element_id 字符串)'), sa.Column('user_id', sa.String(length=36), nullable=False, comment='关联用户 ID'), sa.Column('name', sa.String(length=64), nullable=False, comment='形象展示名称'), sa.Column('voice_id', sa.String(length=64), nullable=True, comment='Kling 自定义音色 ID'), sa.Column('element_id', sa.BigInteger(), nullable=True, comment='Kling 主体 ID'), sa.Column('voice_task_id', sa.String(length=128), nullable=True, comment='Kling 自定义音色任务 ID'), sa.Column('element_task_id', sa.String(length=128), nullable=True, comment='Kling 主体创建任务 ID'), sa.Column('video_url', sa.Text(), nullable=False, comment='原始人物视频 URL'), sa.Column('trial_url', sa.Text(), nullable=True, comment='音色试听音频 URL'), sa.Column('status', sa.String(length=32), nullable=False, comment='状态: pending/voice_processing/voice_failed/element_processing/element_failed/succeed/timeout'), sa.Column('fail_reason', sa.Text(), nullable=True, comment='失败原因(中文可读)'), sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True, comment='软删除时间,NULL 表示未删除'), sa.Column('created_at', sa.DateTime(timezone=True), nullable=False, comment='记录创建时间'), sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False, comment='记录更新时间'), sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_avatars_element_task_id'), 'avatars', ['element_task_id'], unique=False) op.create_index(op.f('ix_avatars_user_id'), 'avatars', ['user_id'], unique=False) op.create_index(op.f('ix_avatars_voice_task_id'), 'avatars', ['voice_task_id'], unique=False) # ### end Alembic commands ### def downgrade() -> None: """Downgrade schema.""" # ### commands auto generated by Alembic - please adjust! ### op.drop_index(op.f('ix_avatars_voice_task_id'), table_name='avatars') op.drop_index(op.f('ix_avatars_user_id'), table_name='avatars') op.drop_index(op.f('ix_avatars_element_task_id'), table_name='avatars') op.drop_table('avatars') # ### end Alembic commands ###