"""add page_config_id to orders, market_place_id to cart_items

Revision ID: c3d4e5f6a7b8
Revises: b2c3d4e5f6a7
Create Date: 2026-02-10
"""
from alembic import op
import sqlalchemy as sa

revision = 'c3d4e5f6a7b8'
down_revision = 'b2c3d4e5f6a7'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # 1. Add market_place_id to cart_items
    op.add_column(
        'cart_items',
        sa.Column('market_place_id', sa.Integer(), nullable=True),
    )
    op.create_foreign_key(
        'fk_cart_items_market_place_id',
        'cart_items',
        'market_places',
        ['market_place_id'],
        ['id'],
        ondelete='SET NULL',
    )
    op.create_index('ix_cart_items_market_place_id', 'cart_items', ['market_place_id'])

    # 2. Add page_config_id to orders
    op.add_column(
        'orders',
        sa.Column('page_config_id', sa.Integer(), nullable=True),
    )
    op.create_foreign_key(
        'fk_orders_page_config_id',
        'orders',
        'page_configs',
        ['page_config_id'],
        ['id'],
        ondelete='SET NULL',
    )
    op.create_index('ix_orders_page_config_id', 'orders', ['page_config_id'])


def downgrade() -> None:
    op.drop_index('ix_orders_page_config_id', table_name='orders')
    op.drop_constraint('fk_orders_page_config_id', 'orders', type_='foreignkey')
    op.drop_column('orders', 'page_config_id')

    op.drop_index('ix_cart_items_market_place_id', table_name='cart_items')
    op.drop_constraint('fk_cart_items_market_place_id', 'cart_items', type_='foreignkey')
    op.drop_column('cart_items', 'market_place_id')
