"""Add missing board columns that the ORM model expects but DB lacks.

The boards model has several fields (description, approval/review rules,
status change blocking, lead-only status changes) that were never
migrated into the database schema.

Revision ID: e5b6c7d8f9a0
Revises: d2a3b4c5e6f7
Create Date: 2026-05-21 04:35:00.000000

"""

from __future__ import annotations

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = "e5b6c7d8f9a0"
down_revision = "d2a3b4c5e6f7"
branch_labels = None
depends_on = None


def upgrade() -> None:
    """Add missing columns to boards."""
    op.add_column("boards", sa.Column("description", sa.String(), nullable=True, server_default=""))
    op.add_column("boards", sa.Column("require_approval_for_done", sa.Boolean(), nullable=False, server_default="true"))
    op.add_column("boards", sa.Column("require_review_before_done", sa.Boolean(), nullable=False, server_default="false"))
    op.add_column("boards", sa.Column("block_status_changes_with_pending_approval", sa.Boolean(), nullable=False, server_default="false"))
    op.add_column("boards", sa.Column("only_lead_can_change_status", sa.Boolean(), nullable=False, server_default="false"))

    # Drop server defaults after adding with them (so existing rows get values)
    op.alter_column("boards", "description", server_default=None)
    op.alter_column("boards", "require_approval_for_done", server_default=None)
    op.alter_column("boards", "require_review_before_done", server_default=None)
    op.alter_column("boards", "block_status_changes_with_pending_approval", server_default=None)
    op.alter_column("boards", "only_lead_can_change_status", server_default=None)


def downgrade() -> None:
    """Remove the columns added in this migration."""
    op.drop_column("boards", "only_lead_can_change_status")
    op.drop_column("boards", "block_status_changes_with_pending_approval")
    op.drop_column("boards", "require_review_before_done")
    op.drop_column("boards", "require_approval_for_done")
    op.drop_column("boards", "description")