"""Make Checkout.amount and Checkout.currency non-nullable

Revision ID: da0ad0290fb4
Revises: d62a0050666e
Create Date: 2025-03-26 15:37:00.479954

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "da0ad0290fb4"
down_revision = "d62a0050666e"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("UPDATE checkouts SET amount = 0 WHERE amount IS NULL")
    op.execute("UPDATE checkouts SET currency = 'usd' WHERE currency IS NULL")
    op.alter_column("checkouts", "amount", existing_type=sa.INTEGER(), nullable=False)
    op.alter_column(
        "checkouts", "currency", existing_type=sa.VARCHAR(length=3), nullable=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "checkouts", "currency", existing_type=sa.VARCHAR(length=3), nullable=True
    )
    op.alter_column("checkouts", "amount", existing_type=sa.INTEGER(), nullable=True)
    # ### end Alembic commands ###
