"""store_mapping 加京东原料列(jd_vender_id + 分享链/反查 URL/deeplink)

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

京东秒送接入店内搜索 deeplink 链路: 3.cn 短链 → 跟随重定向反查 venderId+storeId →
openapp.jdmobile:// deeplink。京东店铺身份是**两个**稳定数字 id: storeId 进 id_jd(稳定
店主键, 同 taobao 的 shopId→id_taobao), venderId 进单列 jd_vender_id(deeplink 还需它)。
其余三列与 taobao_*/meituan_* 原料列平行。
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'store_mapping_jd_cols'
down_revision: Union[str, Sequence[str], None] = 'store_mapping_meituan_cols'
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('jd_vender_id', sa.String(length=64), nullable=True))
        batch_op.add_column(sa.Column('jd_share_url', sa.String(length=256), nullable=True))
        batch_op.add_column(sa.Column('jd_resolved_url', sa.Text(), nullable=True))
        batch_op.add_column(sa.Column('jd_deeplink', sa.Text(), nullable=True))
        batch_op.create_index(batch_op.f('ix_store_mapping_jd_vender_id'), ['jd_vender_id'], 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_jd_vender_id'))
        batch_op.drop_column('jd_deeplink')
        batch_op.drop_column('jd_resolved_url')
        batch_op.drop_column('jd_share_url')
        batch_op.drop_column('jd_vender_id')
