"""savings_record.shop_name + dishes(订单明细卡:店铺名 + 菜品列表)

Revision ID: b1c2d3e4f5a6
Revises: a7c8d9e0f1b2
Create Date: 2026-05-26 10:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    with op.batch_alter_table('savings_record', schema=None) as batch_op:
        batch_op.add_column(sa.Column('shop_name', sa.String(length=128), nullable=True))
        # dishes 存 JSON(SQLite 落 TEXT);旧行给 '[]' 默认,满足 NOT NULL
        batch_op.add_column(
            sa.Column('dishes', sa.JSON(), nullable=False, server_default=sa.text("'[]'"))
        )


def downgrade() -> None:
    with op.batch_alter_table('savings_record', schema=None) as batch_op:
        batch_op.drop_column('dishes')
        batch_op.drop_column('shop_name')
