"""Seed the T-1 terminal-delete preview scheduled job. Seeds ``hr.offboarding_delete_preview`` (daily 23:30 UTC — the evening BEFORE the 03:00 / 03:10 delete sweeps, so the warning lands while there is still a working day in which to act on it). Why the job exists: both terminal-delete sweeps tell nobody on success. An account is permanently gone (Zoom) or enters a ~20-day recovery window (Google) with no human ever given a chance to intervene — the failure notifier only fires on errors, so the *correct* path was the silent one. The digest also states what no API can fix: Gmail message content is not transferable (Data Transfer moves Drive + Calendar only), so a mailbox that must be preserved has to be marked retained BEFORE the delete. Config: ``{"google_lead_days": 2, "zoom_lead_days": 2}`` — keep these in step with the two delete jobs' own ``delete_lead_days`` or the preview will warn about the wrong day. Revision ID: 468 Revises: 467 """ import uuid import sqlalchemy as sa from alembic import op revision = "468" down_revision = "467" branch_labels = None depends_on = None JOB = "hr.offboarding_delete_preview" def upgrade() -> None: bind = op.get_bind() job_exists = bind.execute( sa.text("SELECT 1 FROM scheduled_jobs WHERE name = :n LIMIT 1"), {"n": JOB}, ).scalar() if not job_exists: 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, :name, 'cron', NULL, '30 23 * * *', 'UTC', 1, :config, 0, 0, NOW(), NOW()) """ ), { "id": str(uuid.uuid4()), "name": JOB, "display_name": "离职删号 T-1 预告", "description": ( "每日 23:30 UTC(在次日 03:00 / 03:10 的终删任务之前)" "给 IT 发一条汇总:明天将硬删除哪些离职账号,以及每个账号" "的数据交接是否到位(有无交接人 / Drive 转移是否已完成)。" "并明确提示 Gmail 邮件内容不可转移,要保留必须在删除前把" "邮箱标为保留。每个账号只预告一次。" ), "config": '{"google_lead_days": 2, "zoom_lead_days": 2}', }, ) def downgrade() -> None: bind = op.get_bind() bind.execute(sa.text("DELETE FROM scheduled_jobs WHERE name = :n"), {"n": JOB})