"""添加提示词工坊相关表结构 Revision ID: 927bcb55b756 Revises: 951919659e0f Create Date: 2026-01-27 13:54:34.486645 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = '927bcb55b756' down_revision: Union[str, None] = '951919659e0f' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.create_table('prompt_submissions', sa.Column('id', sa.String(length=36), nullable=False, comment='UUID'), sa.Column('submitter_id', sa.String(length=255), nullable=False, comment='提交者标识(实例ID:用户ID)'), sa.Column('submitter_name', sa.String(length=100), nullable=True, comment='提交者显示名称'), sa.Column('source_instance', sa.String(length=255), nullable=False, comment='来源实例标识'), sa.Column('name', sa.String(length=100), nullable=False, comment='提示词名称'), sa.Column('description', sa.Text(), nullable=True, comment='提示词描述'), sa.Column('prompt_content', sa.Text(), nullable=False, comment='提示词内容'), sa.Column('category', sa.String(length=50), nullable=True, comment='分类'), sa.Column('tags', sa.JSON(), nullable=True, comment='标签数组'), sa.Column('author_display_name', sa.String(length=100), nullable=True, comment='希望显示的作者名'), sa.Column('is_anonymous', sa.Boolean(), nullable=True, comment='是否匿名发布'), sa.Column('status', sa.String(length=20), nullable=True, comment='状态:pending/approved/rejected'), sa.Column('reviewer_id', sa.String(length=100), nullable=True, comment='审核人ID(云端管理员)'), sa.Column('review_note', sa.Text(), nullable=True, comment='审核备注(拒绝理由等)'), sa.Column('reviewed_at', sa.DateTime(), nullable=True, comment='审核时间'), sa.Column('workshop_item_id', sa.String(length=36), nullable=True, comment='审核通过后关联的工坊条目ID'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True, comment='更新时间'), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('prompt_submissions', schema=None) as batch_op: batch_op.create_index('idx_submissions_created_at', ['created_at'], unique=False) batch_op.create_index('idx_submissions_source', ['source_instance'], unique=False) batch_op.create_index('idx_submissions_status', ['status'], unique=False) batch_op.create_index('idx_submissions_submitter', ['submitter_id'], unique=False) op.create_table('prompt_workshop_items', sa.Column('id', sa.String(length=36), nullable=False, comment='UUID'), sa.Column('name', sa.String(length=100), nullable=False, comment='提示词名称'), sa.Column('description', sa.Text(), nullable=True, comment='提示词描述'), sa.Column('prompt_content', sa.Text(), nullable=False, comment='提示词内容'), sa.Column('category', sa.String(length=50), nullable=True, comment='分类'), sa.Column('tags', sa.JSON(), nullable=True, comment='标签数组'), sa.Column('author_id', sa.String(length=255), nullable=True, comment='作者用户标识(实例ID:用户ID)'), sa.Column('author_name', sa.String(length=100), nullable=True, comment='作者显示名称'), sa.Column('source_instance', sa.String(length=255), nullable=True, comment='来源实例标识'), sa.Column('is_official', sa.Boolean(), nullable=True, comment='是否官方提示词'), sa.Column('download_count', sa.Integer(), nullable=True, comment='下载/导入次数'), sa.Column('like_count', sa.Integer(), nullable=True, comment='点赞数'), sa.Column('status', sa.String(length=20), nullable=True, comment='状态:active/hidden/deprecated'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True, comment='更新时间'), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('prompt_workshop_items', schema=None) as batch_op: batch_op.create_index('idx_workshop_items_category', ['category'], unique=False) batch_op.create_index('idx_workshop_items_created_at', ['created_at'], unique=False) batch_op.create_index('idx_workshop_items_download_count', ['download_count'], unique=False) batch_op.create_index('idx_workshop_items_status', ['status'], unique=False) op.create_table('prompt_workshop_likes', sa.Column('id', sa.String(length=36), nullable=False, comment='UUID'), sa.Column('user_identifier', sa.String(length=255), nullable=False, comment='用户标识(实例ID:用户ID)'), sa.Column('workshop_item_id', sa.String(length=36), nullable=False, comment='工坊条目ID'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True, comment='创建时间'), sa.ForeignKeyConstraint(['workshop_item_id'], ['prompt_workshop_items.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('prompt_workshop_likes', schema=None) as batch_op: batch_op.create_index('idx_likes_user_item', ['user_identifier', 'workshop_item_id'], unique=True) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('prompt_workshop_likes', schema=None) as batch_op: batch_op.drop_index('idx_likes_user_item') op.drop_table('prompt_workshop_likes') with op.batch_alter_table('prompt_workshop_items', schema=None) as batch_op: batch_op.drop_index('idx_workshop_items_status') batch_op.drop_index('idx_workshop_items_download_count') batch_op.drop_index('idx_workshop_items_created_at') batch_op.drop_index('idx_workshop_items_category') op.drop_table('prompt_workshop_items') with op.batch_alter_table('prompt_submissions', schema=None) as batch_op: batch_op.drop_index('idx_submissions_submitter') batch_op.drop_index('idx_submissions_status') batch_op.drop_index('idx_submissions_source') batch_op.drop_index('idx_submissions_created_at') op.drop_table('prompt_submissions') # ### end Alembic commands ###