"""Add is_private field to events

Revision ID: 89527c8da8e1
Revises: 
Create Date: 2026-01-25 18:43:00.881982

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '89527c8da8e1'
down_revision: Union[str, None] = '0001_initial'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # Ajouter la colonne avec nullable=True d'abord
    op.add_column('events', sa.Column('is_private', sa.Boolean(), nullable=True))
    # Mettre à jour toutes les lignes existantes avec False
    op.execute("UPDATE events SET is_private = FALSE WHERE is_private IS NULL")
    # Rendre la colonne non-nullable avec une valeur par défaut
    op.alter_column('events', 'is_private',
                    existing_type=sa.Boolean(),
                    nullable=False,
                    server_default='false')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('events', 'is_private')
    # ### end Alembic commands ###
