"""Add rate_limit_group

Revision ID: da0275629643
Revises: 9919760fc6cb
Create Date: 2025-08-20 13:32:44.025958

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "da0275629643"
down_revision = "9919760fc6cb"
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(
        "oauth2_clients",
        sa.Column("rate_limit_group", sa.String(length=16), nullable=True),
    )
    op.execute(
        "UPDATE oauth2_clients SET rate_limit_group = 'default' WHERE rate_limit_group IS NULL"
    )
    op.alter_column(
        "oauth2_clients",
        "rate_limit_group",
        existing_type=sa.String(length=16),
        nullable=False,
    )

    op.add_column(
        "organizations",
        sa.Column("rate_limit_group", sa.String(length=16), nullable=True),
    )
    op.execute(
        "UPDATE organizations SET rate_limit_group = 'default' WHERE rate_limit_group IS NULL"
    )
    op.alter_column(
        "organizations",
        "rate_limit_group",
        existing_type=sa.String(length=16),
        nullable=False,
    )
    # ### end Alembic commands ###


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