"""新增 price_report 上报更低价表

Revision ID: 9258bddde4ea
Revises: ad60a1b2c3d4
Create Date: 2026-06-05 10:15:51.508598

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '9258bddde4ea'
down_revision: Union[str, Sequence[str], None] = 'ad60a1b2c3d4'
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('price_report',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('comparison_record_id', sa.Integer(), nullable=True),
    sa.Column('store_name', sa.String(length=128), nullable=True),
    sa.Column('dish_summary', sa.String(length=256), nullable=True),
    sa.Column('original_platform_id', sa.String(length=32), nullable=True),
    sa.Column('original_platform_name', sa.String(length=32), nullable=True),
    sa.Column('original_price_cents', sa.Integer(), nullable=True),
    sa.Column('reported_platform_id', sa.String(length=32), nullable=False),
    sa.Column('reported_platform_name', sa.String(length=32), nullable=False),
    sa.Column('reported_price_cents', sa.Integer(), nullable=False),
    sa.Column('images', sa.JSON(), nullable=False),
    sa.Column('status', sa.String(length=16), nullable=False),
    sa.Column('reject_reason', sa.String(length=256), nullable=True),
    sa.Column('reward_coins', sa.Integer(), nullable=True),
    sa.Column('reviewed_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
    sa.ForeignKeyConstraint(['comparison_record_id'], ['comparison_record.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('price_report', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_price_report_comparison_record_id'), ['comparison_record_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_price_report_created_at'), ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_price_report_status'), ['status'], unique=False)
        batch_op.create_index(batch_op.f('ix_price_report_user_id'), ['user_id'], unique=False)
    # 注:autogenerate 另检测到「删除 order_record 表」——那是已降级为审计的历史表
    #     (model 已移除、库表保留),与本次无关,手动剔除,避免误删他人审计数据。
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # (对称:upgrade 未删 order_record,downgrade 也不重建它)
    with op.batch_alter_table('price_report', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_price_report_user_id'))
        batch_op.drop_index(batch_op.f('ix_price_report_status'))
        batch_op.drop_index(batch_op.f('ix_price_report_created_at'))
        batch_op.drop_index(batch_op.f('ix_price_report_comparison_record_id'))

    op.drop_table('price_report')
    # ### end Alembic commands ###
