"""make payer_id nullable in payment_requests_authorizations

Revision ID: fix001_payer_id_nullable_auth
Revises: ba03f6304d85
Create Date: 2026-04-08

The payment_requests_authorizations.payer_id column was created as NOT NULL
in the initial migration (9d1894ff8a05_recent_tables.py) but the ORM model
defines it as Optional/nullable. This mismatch causes a 500 when creating
payment requests with authorization_type=pre_auth (CHECKBOX) because payer_id
is not available at creation time.
"""

from typing import Union, Sequence
from alembic import op
import sqlalchemy as sa

revision: str = "fix001_payer_id_nullable_auth"
down_revision: Union[str, Sequence[str], None] = "ba03f6304d85"
depends_on = None


def upgrade() -> None:
    op.alter_column(
        "payment_requests_authorizations",
        "payer_id",
        existing_type=sa.Integer(),
        nullable=True,
    )


def downgrade() -> None:
    # Only safe to revert if no NULLs exist; intentionally left as nullable
    op.alter_column(
        "payment_requests_authorizations",
        "payer_id",
        existing_type=sa.Integer(),
        nullable=False,
    )
