"""增加生成图片的比例像素

Revision ID: 5d2db654417b
Revises: d54d06438b25
Create Date: 2026-05-19 17:51:16.099136
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def _has_column(table_name: str, column_name: str) -> bool:
    bind = op.get_bind()
    inspector = sa.inspect(bind)
    columns = inspector.get_columns(table_name)
    return any(col["name"] == column_name for col in columns)


def upgrade() -> None:
    if not _has_column("generation_records", "image_proportion"):
        op.add_column('generation_records', sa.Column('image_proportion', sa.String(length=8), nullable=True))

    if not _has_column("generation_records", "image_px"):
        op.add_column('generation_records', sa.Column('image_px', sa.String(length=10), nullable=True))


def downgrade() -> None:
    if _has_column("generation_records", "image_px"):
        op.drop_column('generation_records', 'image_px')

    if _has_column("generation_records", "image_proportion"):
        op.drop_column('generation_records', 'image_proportion')