"""add_recipient_type_to_campaigns

Revision ID: 87e29a777cb3
Revises: 316d876b1b71
Create Date: 2025-12-05 15:36:11.095669

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '87e29a777cb3'
down_revision = '316d876b1b71'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # Add recipient_type column to email_campaigns table
    from sqlalchemy import inspect
    conn = op.get_bind()
    inspector = inspect(conn)
    
    # Check if column exists
    columns = [col['name'] for col in inspector.get_columns('email_campaigns')]
    if 'recipient_type' not in columns:
        op.add_column('email_campaigns', sa.Column('recipient_type', sa.String(50), nullable=True, server_default='users'))


def downgrade() -> None:
    # Remove recipient_type column
    from sqlalchemy import inspect
    conn = op.get_bind()
    inspector = inspect(conn)
    
    columns = [col['name'] for col in inspector.get_columns('email_campaigns')]
    if 'recipient_type' in columns:
        op.drop_column('email_campaigns', 'recipient_type')

