"""add_educational_partner_user_type

Revision ID: add_educational_partner
Revises: b2af37736ec8
Create Date: 2026-01-26 10:00:00.000000

PostgreSQL enum value additions must run outside a transaction block.
Use Alembic's autocommit_block to execute ALTER TYPE safely.
"""
from typing import Sequence, Union

from alembic import op


# revision identifiers, used by Alembic.
revision: str = 'add_educational_partner'
down_revision: Union[str, Sequence[str], None] = 'b2af37736ec8'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema - add EDUCATIONAL_PARTNER to UserType enum."""
    # Run outside transaction; IF NOT EXISTS makes it idempotent for re-runs.
    with op.get_context().autocommit_block():
        op.execute("ALTER TYPE usertype ADD VALUE IF NOT EXISTS 'EDUCATIONAL_PARTNER'")


def downgrade() -> None:
    """Downgrade schema - remove EDUCATIONAL_PARTNER from UserType enum."""
    # Note: PostgreSQL doesn't support removing enum values directly
    # This would require recreating the enum type and updating all references
    # For safety, we'll leave this as a no-op
    # In production, you would need to:
    # 1. Create a new enum without EDUCATIONAL_PARTNER
    # 2. Update all user_type columns to use the new enum
    # 3. Drop the old enum
    pass
