-- Migration: 000144_training_wecom_push -- WeCom proactive push for training reminders. -- 1) org_employees.wecom_userid maps a platform user (users.id via user_id) -- to the WeCom (企业微信) userid used by /cgi-bin/message/send touser. -- 2) tr_notifications gains an outbox: rows generated with push_status='pending' -- are delivered by the training scheduler; '' means no WeCom push needed. DO $$ BEGIN RAISE NOTICE '[Migration 000144] Adding training WeCom push columns...'; END $$; ALTER TABLE org_employees ADD COLUMN IF NOT EXISTS wecom_userid VARCHAR(64) NOT NULL DEFAULT ''; ALTER TABLE tr_notifications ADD COLUMN IF NOT EXISTS push_status VARCHAR(16) NOT NULL DEFAULT '', ADD COLUMN IF NOT EXISTS push_attempts INT NOT NULL DEFAULT 0, ADD COLUMN IF NOT EXISTS pushed_at TIMESTAMPTZ, ADD COLUMN IF NOT EXISTS push_error TEXT DEFAULT ''; CREATE INDEX IF NOT EXISTS idx_tr_notifications_push_pending ON tr_notifications(created_at) WHERE push_status = 'pending' AND deleted_at IS NULL; COMMENT ON COLUMN org_employees.wecom_userid IS 'WeCom userid for proactive message/send push; empty = not bound'; COMMENT ON COLUMN tr_notifications.push_status IS 'WeCom delivery outbox state: empty=none, pending, sending, sent, skipped, dead';