"""Add Organization.subscriptions_billing_engine

Revision ID: 71dd42ca673e
Revises: 3d67a4eb268a
Create Date: 2025-07-10 11:22:16.789179

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "71dd42ca673e"
down_revision = "3d67a4eb268a"
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(
        "organizations",
        sa.Column("subscriptions_billing_engine", sa.Boolean(), nullable=True),
    )

    op.execute(
        """
        UPDATE organizations
        SET subscriptions_billing_engine = FALSE
        WHERE subscriptions_billing_engine IS NULL
        """
    )

    op.alter_column(
        "organizations",
        "subscriptions_billing_engine",
        existing_type=sa.Boolean(),
        nullable=False,
    )

    # ### end Alembic commands ###


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