"""screens.published — draft vs published

Revision ID: e40a7c92b1d8
Revises: d18b3c6f9a72
Create Date: 2026-09-02

A screen being worked on is ours alone; the client sees it when we say so.

Backfilled TRUE: every screen that already exists was visible to the client, and
a migration must not make things vanish from a live board. The model default is
false, so only NEW screens start as drafts.
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = 'e40a7c92b1d8'
down_revision: Union[str, Sequence[str], None] = 'd18b3c6f9a72'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column('screens', sa.Column('published', sa.Boolean(), nullable=False,
                                       server_default=sa.true()))
    # Drop the server default so the column has no opinion of its own; new rows
    # take the model's default, which is draft. SQLite cannot ALTER a column —
    # and does not need to, because SQLAlchemy always sends `published`
    # explicitly on insert, so the server default is never what decides.
    if op.get_bind().dialect.name != "sqlite":
        op.alter_column('screens', 'published', server_default=None)


def downgrade() -> None:
    op.drop_column('screens', 'published')
