"""Add Organization.subscription_settings

Revision ID: d25d25af882a
Revises: 9c158a0aadf5
Create Date: 2025-01-28 08:59:27.471274

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "d25d25af882a"
down_revision = "9c158a0aadf5"
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(
            "subscription_settings",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
    )

    op.execute(
        """
        UPDATE organizations
        SET subscription_settings = '{"allow_multiple_subscriptions": true, "allow_customer_updates": true, "proration_behavior": "prorate"}'
        """
    )

    op.alter_column("organizations", "subscription_settings", nullable=False)

    # ### end Alembic commands ###


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