"""add notification settings to org model

Revision ID: 4b8976c08210
Revises: c2d5a5c0b974
Create Date: 2025-07-03 16:00:36.179114

"""

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

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "4b8976c08210"
down_revision = "c2d5a5c0b974"
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(
            "notification_settings",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
    )

    op.execute(
        """
        UPDATE organizations
        SET notification_settings = '{"new_order": true, "new_subscription": true}'
        """
    )

    op.alter_column("organizations", "notification_settings", nullable=False)
    # ### end Alembic commands ###


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