51 lines
2.4 KiB
Python
51 lines
2.4 KiB
Python
"""add suggestions table
|
|
|
|
Revision ID: e5f7a9b1cd35
|
|
Revises: e5f7a9b1cd34
|
|
Create Date: 2025-01-20 10:00:00.000000
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
|
|
|
# revision identifiers
|
|
revision = "e5f7a9b1cd35"
|
|
down_revision = "e5f7a9b1cd34"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"suggestions",
|
|
sa.Column("id", UUID(as_uuid=True), primary_key=True),
|
|
sa.Column("brand_id", UUID(as_uuid=True), sa.ForeignKey("brands.id", ondelete="CASCADE"), nullable=False),
|
|
sa.Column("type", sa.String(50), nullable=False, comment="建议类型"),
|
|
sa.Column("priority", sa.String(20), nullable=False, server_default="medium", comment="优先级"),
|
|
sa.Column("title", sa.String(200), nullable=False),
|
|
sa.Column("description", sa.Text, nullable=False),
|
|
sa.Column("action", sa.Text, nullable=True, comment="具体操作步骤"),
|
|
sa.Column("expected_impact", sa.String(200), nullable=True, comment="预期效果"),
|
|
sa.Column("difficulty", sa.String(20), nullable=False, server_default="medium", comment="难度"),
|
|
sa.Column("status", sa.String(20), nullable=False, server_default="pending", comment="状态"),
|
|
sa.Column("generated_at", sa.DateTime, server_default=sa.func.now(), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime, server_default=sa.func.now(), onupdate=sa.func.now(), nullable=False),
|
|
sa.Column("batch_id", UUID(as_uuid=True), nullable=False),
|
|
sa.Column("source", sa.String(20), nullable=False, server_default="rule", comment="生成来源"),
|
|
)
|
|
|
|
op.create_index("idx_suggestions_brand_id", "suggestions", ["brand_id"])
|
|
op.create_index("idx_suggestions_status", "suggestions", ["status"])
|
|
op.create_index("idx_suggestions_type", "suggestions", ["type"])
|
|
op.create_index("idx_suggestions_batch_id", "suggestions", ["batch_id"])
|
|
op.create_index("idx_suggestions_brand_status", "suggestions", ["brand_id", "status"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("idx_suggestions_brand_status", table_name="suggestions")
|
|
op.drop_index("idx_suggestions_batch_id", table_name="suggestions")
|
|
op.drop_index("idx_suggestions_type", table_name="suggestions")
|
|
op.drop_index("idx_suggestions_status", table_name="suggestions")
|
|
op.drop_index("idx_suggestions_brand_id", table_name="suggestions")
|
|
op.drop_table("suggestions")
|