Files
Neo-ZQYY/db/zqyy_app/migrations/2026-02-27__p4_seed_trigger_jobs.sql

44 lines
2.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =============================================================================
-- 迁移脚本:预置触发器配置种子数据
-- 日期2026-02-27
-- 目标库test_zqyy_app通过 APP_DB_DSN 连接)
-- 说明:在 biz.trigger_jobs 表中插入 4 条核心触发器配置,
-- 驱动任务生成、有效期检查、召回完成检测、备注回溯重分类。
-- 前提biz.trigger_jobs 表已由 2026-02-27__p4_create_biz_tables.sql 创建
-- 需求2.1, 2.2, 2.3, 2.4, 2.5
-- =============================================================================
INSERT INTO biz.trigger_jobs (job_type, job_name, trigger_condition, trigger_config, next_run_at)
VALUES
-- 1. task_generator每日凌晨 4:00 运行,基于 WBI/NCI/RS 指数为助教生成任务
('task_generator', 'task_generator', 'cron',
'{"cron_expression": "0 4 * * *"}',
(CURRENT_DATE + 1) + INTERVAL '4 hours'),
-- 2. task_expiry_check每小时运行检查 expires_at 到期的任务并标记 inactive
('task_expiry_check', 'task_expiry_check', 'interval',
'{"interval_seconds": 3600}',
NOW() + INTERVAL '1 hour'),
-- 3. recall_completion_checkETL 数据更新后触发,检测助教服务记录匹配活跃任务
('recall_completion_check', 'recall_completion_check', 'event',
'{"event_name": "etl_data_updated"}',
NULL),
-- 4. note_reclassify_backfill召回完成后触发回溯重分类普通备注为回访备注
('note_reclassify_backfill', 'note_reclassify_backfill', 'event',
'{"event_name": "recall_completed"}',
NULL)
ON CONFLICT (job_name) DO NOTHING;
-- =============================================================================
-- 回滚脚本
-- =============================================================================
-- DELETE FROM biz.trigger_jobs
-- WHERE job_name IN (
-- 'task_generator',
-- 'task_expiry_check',
-- 'recall_completion_check',
-- 'note_reclassify_backfill'
-- );