"""added     is2FAEnabled     = Column(Boolean, default=False,nullable=False)

Revision ID: 3c014ba418e2
Revises: 33fbc83d7cbf
Create Date: 2025-05-10 17:17:50.409985

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '3c014ba418e2'
down_revision: Union[str, None] = '33fbc83d7cbf'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Step 1: Add the columns as nullable
    op.add_column('companies', sa.Column('is2FAEnabled', sa.Boolean(), nullable=True))
    op.add_column('users', sa.Column('is2FAEnabled', sa.Boolean(), nullable=True))

    # Step 2: Set default values for existing records
    op.execute('UPDATE companies SET "is2FAEnabled" = false')
    op.execute('UPDATE users SET "is2FAEnabled" = false')

    # Step 3: Alter columns to be NOT NULL
    op.alter_column('companies', 'is2FAEnabled', nullable=False)
    op.alter_column('users', 'is2FAEnabled', nullable=False)


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