"""phase_3_staff_ui_prefs

Adds ui_prefs JSONB column to the staff table (Phase 3 — staff auth cutover).
Also corrects permissions to be nullable (sysadmin/admin have NULL permissions).

Revision ID: c3d4e5f6a7b8
Revises: b1c2d3e4f5a6
Create Date: 2026-04-17 00:00:00.000000
"""
from typing import Sequence, Union
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import JSONB
from alembic import op

revision: str = "c3d4e5f6a7b8"
down_revision: Union[str, None] = "b1c2d3e4f5a6"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "staff",
        sa.Column("ui_prefs", JSONB, nullable=False, server_default="{}"),
    )
    # permissions was NOT NULL DEFAULT '{}' — relax to nullable for sysadmin/admin
    op.alter_column("staff", "permissions", nullable=True)


def downgrade() -> None:
    op.drop_column("staff", "ui_prefs")
    op.alter_column("staff", "permissions", nullable=False)
