"""add benefit_revocation_grace_period to organization subscription settings

Revision ID: df6c0fa5e0e9
Revises: edf952c2129a
Create Date: 2025-10-28 10:43:21.592306

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

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


def upgrade() -> None:
    # Add benefit_revocation_grace_period to all existing organizations
    # Default value is 0 (immediate) to maintain current behavior
    op.execute("""
        UPDATE organizations
        SET subscription_settings = subscription_settings || '{"benefit_revocation_grace_period": 0}'::jsonb
        WHERE subscription_settings IS NOT NULL
          AND NOT subscription_settings ? 'benefit_revocation_grace_period'
    """)


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###
