"""Seed the (disabled) jamf.seat_sync recurring scheduled job. Daily 03:00 UTC, same off-peak window as the other seat-syncs (Feishu / Jira / Slack / Zoom / Google). Seeded DISABLED — an admin enables it after binding the "Jamf" software to the Jamf MDM integration via a SoftwareConnector. Disabled-on-seed keeps the worker's pre-boot "every enabled job has a registered handler" guard happy regardless of deploy ordering. Idempotent: INSERTed only if handler_key isn't already present. Uses a hyphenated ``str(uuid.uuid4())`` for the id — NOT the dash-stripped 32-char UUID form, which strands the cron (see fixes 059 / 162 / 246). """ from __future__ import annotations import uuid import sqlalchemy as sa from alembic import op revision = "346" down_revision = "345" branch_labels = None depends_on = None _JOB = "jamf.seat_sync" def upgrade() -> None: bind = op.get_bind() exists = bind.execute( sa.text("SELECT 1 FROM scheduled_jobs WHERE handler_key = :k"), {"k": _JOB}, ).scalar() if exists: return bind.execute( sa.text( """ INSERT INTO scheduled_jobs (id, name, display_name, description, handler_key, trigger_type, interval_seconds, cron_expr, timezone, enabled, config, run_count, failure_count, created_at, updated_at) VALUES (:id, :name, :display_name, :description, :handler_key, 'cron', NULL, '0 3 * * *', 'UTC', 0, '{}', 0, 0, NOW(), NOW()) """ ), { "id": str(uuid.uuid4()), "name": _JOB, "display_name": "Jamf · 设备席位同步", "description": ( "拉取 Jamf 已纳管设备喂进统一坐席对账(席位=设备)+ 维护人↔席位" "分配与灰度漂移回收。启用前需把「Jamf」软件绑定到 Jamf MDM 连接器。" ), "handler_key": _JOB, }, ) def downgrade() -> None: bind = op.get_bind() bind.execute( sa.text("DELETE FROM scheduled_jobs WHERE handler_key = :k"), {"k": _JOB}, )