"""Make Subscription amount and currency non nullable

Revision ID: fcd7238f2659
Revises: bb928a32f068
Create Date: 2025-03-11 11:17:41.635510

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "fcd7238f2659"
down_revision = "bb928a32f068"
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 subscriptions SET amount = 0 WHERE amount IS NULL")
    op.execute("UPDATE subscriptions SET currency = 'usd' WHERE currency IS NULL")
    op.execute("UPDATE subscription_product_prices SET amount = 0 WHERE amount IS NULL")

    op.alter_column(
        "subscription_product_prices",
        "amount",
        existing_type=sa.INTEGER(),
        nullable=False,
    )
    op.alter_column(
        "subscriptions", "amount", existing_type=sa.INTEGER(), nullable=False
    )
    op.alter_column(
        "subscriptions", "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(
        "subscriptions", "currency", existing_type=sa.VARCHAR(length=3), nullable=True
    )
    op.alter_column(
        "subscriptions", "amount", existing_type=sa.INTEGER(), nullable=True
    )
    op.alter_column(
        "subscription_product_prices",
        "amount",
        existing_type=sa.INTEGER(),
        nullable=True,
    )
    # ### end Alembic commands ###
