diff --git a/backend/alembic/postgres/versions/20260127_1404_421237957b27_添加提示词工坊相关表结构.py b/backend/alembic/postgres/versions/20260127_1404_421237957b27_添加提示词工坊相关表结构.py new file mode 100644 index 0000000..bbccc36 --- /dev/null +++ b/backend/alembic/postgres/versions/20260127_1404_421237957b27_添加提示词工坊相关表结构.py @@ -0,0 +1,96 @@ +"""添加提示词工坊相关表结构 + +Revision ID: 421237957b27 +Revises: 6a73f37e9adb +Create Date: 2026-01-27 14:04:47.054011 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '421237957b27' +down_revision: Union[str, None] = '6a73f37e9adb' +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('now()'), nullable=True, comment='创建时间'), + sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True, comment='更新时间'), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('idx_submissions_created_at', 'prompt_submissions', ['created_at'], unique=False) + op.create_index('idx_submissions_source', 'prompt_submissions', ['source_instance'], unique=False) + op.create_index('idx_submissions_status', 'prompt_submissions', ['status'], unique=False) + op.create_index('idx_submissions_submitter', 'prompt_submissions', ['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('now()'), nullable=True, comment='创建时间'), + sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True, comment='更新时间'), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('idx_workshop_items_category', 'prompt_workshop_items', ['category'], unique=False) + op.create_index('idx_workshop_items_created_at', 'prompt_workshop_items', ['created_at'], unique=False) + op.create_index('idx_workshop_items_download_count', 'prompt_workshop_items', ['download_count'], unique=False) + op.create_index('idx_workshop_items_status', 'prompt_workshop_items', ['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('now()'), nullable=True, comment='创建时间'), + sa.ForeignKeyConstraint(['workshop_item_id'], ['prompt_workshop_items.id'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('idx_likes_user_item', 'prompt_workshop_likes', ['user_identifier', 'workshop_item_id'], unique=True) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index('idx_likes_user_item', table_name='prompt_workshop_likes') + op.drop_table('prompt_workshop_likes') + op.drop_index('idx_workshop_items_status', table_name='prompt_workshop_items') + op.drop_index('idx_workshop_items_download_count', table_name='prompt_workshop_items') + op.drop_index('idx_workshop_items_created_at', table_name='prompt_workshop_items') + op.drop_index('idx_workshop_items_category', table_name='prompt_workshop_items') + op.drop_table('prompt_workshop_items') + op.drop_index('idx_submissions_submitter', table_name='prompt_submissions') + op.drop_index('idx_submissions_status', table_name='prompt_submissions') + op.drop_index('idx_submissions_source', table_name='prompt_submissions') + op.drop_index('idx_submissions_created_at', table_name='prompt_submissions') + op.drop_table('prompt_submissions') + # ### end Alembic commands ### \ No newline at end of file