"""Seed daily deterministic Intelligence snapshots and normalize telemetry UTC. Revision ID: 479 Revises: 478 """ import uuid import sqlalchemy as sa from alembic import op revision = "479" down_revision = "478" branch_labels = None depends_on = None _JOB = "intelligence.snapshot_daily" _TELEMETRY_KEY = "observability.client_error_telemetry_started" def upgrade() -> None: bind = op.get_bind() # Migration 477 used NOW(), whose interpretation follows the session TZ. # The product is still hidden, so reset the warm-up epoch once with an # explicit UTC value before any score can be user-visible. bind.execute( sa.text( "UPDATE platform_settings " "SET created_at = UTC_TIMESTAMP(), updated_at = UTC_TIMESTAMP() " "WHERE `key` = :key" ), {"key": _TELEMETRY_KEY}, ) exists = bind.execute( sa.text("SELECT 1 FROM scheduled_jobs WHERE name = :name LIMIT 1"), {"name": _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, :name, 'cron', NULL, '20 7 * * *', 'UTC', 1, :config, 0, 0, UTC_TIMESTAMP(), UTC_TIMESTAMP()) """ ), { "id": str(uuid.uuid4()), "name": _JOB, "display_name": "AI 大脑每日确定性快照", "description": ( "每日 07:20 UTC 在数据同步窗口后生成八维确定性健康快照;" "同事实 Hash 不新增版本,只保存匿名证据,不调用模型。" ), "config": "{}", }, ) def downgrade() -> None: op.get_bind().execute( sa.text("DELETE FROM scheduled_jobs WHERE name = :name"), {"name": _JOB}, )