"""phase19 — add mobile_photo_paths column to issues table Background ---------- Issues created on the iPad can have multiple evidence photos. The first photo is stored in `photo_path` (existing single-string column). Additional photos were previously stored in `result_photos` (intended for resolution photos), causing them to appear under "Resolution Details" on the web instead of "Photo Evidence". This migration adds `mobile_photo_paths JSON NULL` to store the extra evidence photos from the iPad separately from resolution photos. Safe to re-run — uses INFORMATION_SCHEMA existence check. """ import sqlalchemy as sa from alembic import op revision = 'phase19_issue_mobile_photos' down_revision = 'phase18_issue_reported_by' branch_labels = None depends_on = None def _column_exists(bind, table, column): result = bind.execute(sa.text( "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " "WHERE TABLE_SCHEMA = DATABASE() " "AND TABLE_NAME = :t AND COLUMN_NAME = :c" ), {"t": table, "c": column}) return result.scalar() > 0 def upgrade(): bind = op.get_bind() if not _column_exists(bind, 'issues', 'mobile_photo_paths'): op.add_column('issues', sa.Column( 'mobile_photo_paths', sa.JSON(), nullable=True )) def downgrade(): bind = op.get_bind() if _column_exists(bind, 'issues', 'mobile_photo_paths'): op.execute(sa.text("ALTER TABLE issues DROP COLUMN mobile_photo_paths"))