"""add scratchpad to sessions

Revision ID: 009
Revises: 4cdb5cba1aff
Create Date: 2026-02-04

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '009'
down_revision: Union[str, None] = '4cdb5cba1aff'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column('sessions',
        sa.Column('scratchpad', sa.Text(), nullable=True, server_default=sa.text("''"))
    )
    # Backfill existing rows to empty string (not NULL)
    op.execute("UPDATE sessions SET scratchpad = '' WHERE scratchpad IS NULL")


def downgrade() -> None:
    op.drop_column('sessions', 'scratchpad')
