"""add is_superuser to users

Revision ID: 20260714_0003
Revises: 20260711_0002
Create Date: 2026-07-14 12:45:00
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "20260714_0003"
down_revision: Union[str, None] = "20260711_0002"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "users",
        sa.Column("is_superuser", sa.Boolean(), nullable=False, server_default=sa.false()),
    )
    bind = op.get_bind()
    if bind.dialect.name != "sqlite":
        op.alter_column("users", "is_superuser", server_default=None)
    op.execute(
        sa.text(
            "UPDATE users SET is_superuser = true "
            "WHERE email = 'admin@compton.example' AND role = 'admin'"
        )
    )


def downgrade() -> None:
    op.drop_column("users", "is_superuser")
