"""store_mapping 加美团原料列(poi_id_str + 分享链/反查 URL/deeplink)

Revision ID: store_mapping_meituan_cols
Revises: store_mapping_table
Create Date: 2026-06-13 00:00:00.000000

美团接入店内搜索 deeplink 链路: dpurl.cn 短链 → 302 反查 poi_id_str → imeituan:// deeplink。
poi_id_str 每次分享重新加密、非稳定主键, 单列 meituan_poi_id_str 存(不占 id_meituan,
后者留给将来 CPS API 的稳定数字 poi_id)。其余三列与 taobao_* 原料列平行。
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'store_mapping_meituan_cols'
down_revision: Union[str, Sequence[str], None] = 'store_mapping_table'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    with op.batch_alter_table('store_mapping', schema=None) as batch_op:
        batch_op.add_column(sa.Column('meituan_poi_id_str', sa.String(length=64), nullable=True))
        batch_op.add_column(sa.Column('meituan_share_url', sa.String(length=256), nullable=True))
        batch_op.add_column(sa.Column('meituan_resolved_url', sa.Text(), nullable=True))
        batch_op.add_column(sa.Column('meituan_deeplink', sa.Text(), nullable=True))
        batch_op.create_index(batch_op.f('ix_store_mapping_meituan_poi_id_str'), ['meituan_poi_id_str'], unique=False)


def downgrade() -> None:
    with op.batch_alter_table('store_mapping', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_store_mapping_meituan_poi_id_str'))
        batch_op.drop_column('meituan_deeplink')
        batch_op.drop_column('meituan_resolved_url')
        batch_op.drop_column('meituan_share_url')
        batch_op.drop_column('meituan_poi_id_str')
