"""Re-insert dashes into ``scheduled_jobs.id`` values that landed de-hyphenated. Revision ID: 059 Revises: 058 Create Date: 2026-04-23 Migration 050 seeded ``google.dept_sync`` / ``google.group_sync`` with ``REPLACE(UUID(), '-', '')``, so those two rows got 32-char IDs while the ``scheduled_jobs.id`` column is ``CHAR(36)`` expected to hold the dashed form. Our SQLAlchemy ``GUID`` type normalises inbound lookups through ``uuid.UUID(...)`` → dashed 36-char string, so ``GET /scheduled-jobs/{id}`` queries miss those rows and the UI shows "ScheduledJob '…' not found". Fix: re-hyphenate any rows currently holding a 32-char hex id. Guarded by ``LENGTH(id) = 32 AND id REGEXP '^[0-9a-f]{32}$'`` so we only touch rows that actually look broken; well-formed rows are untouched. """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision = "059" down_revision = "058" branch_labels = None depends_on = None _REHYPHENATE = sa.text( """ UPDATE scheduled_jobs SET id = CONCAT( SUBSTRING(id, 1, 8), '-', SUBSTRING(id, 9, 4), '-', SUBSTRING(id, 13, 4), '-', SUBSTRING(id, 17, 4), '-', SUBSTRING(id, 21, 12) ) WHERE LENGTH(id) = 32 AND id REGEXP '^[0-9a-f]{32}$' """ ) def upgrade() -> None: op.get_bind().execute(_REHYPHENATE) def downgrade() -> None: # No-op: the dashed form is what every other code path expects. Stripping # dashes back out would reintroduce the original bug. pass