"""Add Checkout.require_billing_address

Revision ID: 13c6e2052c0a
Revises: ce111f3235e3
Create Date: 2025-04-18 13:42:19.533586

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "checkout_links",
        sa.Column("require_billing_address", sa.Boolean(), nullable=True),
    )
    op.execute("""UPDATE checkout_links SET require_billing_address = FALSE""")
    op.alter_column(
        "checkout_links",
        "require_billing_address",
        existing_type=sa.Boolean(),
        nullable=False,
    )

    op.add_column(
        "checkouts", sa.Column("require_billing_address", sa.Boolean(), nullable=True)
    )
    op.execute("""UPDATE checkouts SET require_billing_address = FALSE""")
    op.alter_column(
        "checkouts",
        "require_billing_address",
        existing_type=sa.Boolean(),
        nullable=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("checkouts", "require_billing_address")
    op.drop_column("checkout_links", "require_billing_address")
    # ### end Alembic commands ###
