"""widen alembic_version.version_num to 255 Revision ID: 20251107_123000_widen_alembic_version Revises: 20251107_121500_labels_stickers Create Date: 2025-11-07T12:30:00.000000 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = "20251107_123000_widen_alembic_version" down_revision = "20251107_121500_labels_stickers" branch_labels = None depends_on = None def upgrade() -> None: """Increase the size of alembic_version.version_num to 255.""" # Most projects use Postgres; this raw SQL is explicit and works reliably. # Widening requires no USING clause on Postgres, but we'll be explicit for clarity. op.execute( "ALTER TABLE alembic_version " "ALTER COLUMN version_num TYPE VARCHAR(255)" ) # If you need cross-dialect support later, you could add dialect checks # and use batch_alter_table for SQLite. For your Postgres setup, this is sufficient. def downgrade() -> None: """Shrink alembic_version.version_num back to 32. On Postgres, shrinking can fail if any row exceeds 32 chars. We proactively truncate to 32 to guarantee a clean downgrade. """ # Truncate any too-long values to fit back into VARCHAR(32) op.execute( "UPDATE alembic_version SET version_num = LEFT(version_num, 32)" ) op.execute( "ALTER TABLE alembic_version " "ALTER COLUMN version_num TYPE VARCHAR(32)" )