"""notes.display_title Revision ID: 0012 Revises: 0011 Create Date: 2026-07-22 """ from alembic import op import sqlalchemy as sa revision = "0012" down_revision = "0011" branch_labels = None depends_on = None def upgrade() -> None: # The note's display NAME: explicit title if set, else the first body line. op.add_column("notes", sa.Column("display_title", sa.Text(), nullable=False, server_default="")) # Best-effort backfill (kept intentionally simple + unambiguous — CI has no # Postgres lane, so this only runs on a real deploy). The app recomputes the # precise value via derive_display_title on the next save (which additionally # skips leading blank lines). Capped at 200 chars. op.execute( r""" UPDATE notes SET display_title = LEFT(btrim( CASE WHEN title IS NOT NULL AND btrim(title) <> '' THEN title ELSE split_part(body, E'\n', 1) END ), 200) """ ) def downgrade() -> None: op.drop_column("notes", "display_title")