Files
junhong_cmp_fiber/migrations/000115_init_data.up.sql

59 lines
2.6 KiB
SQL
Raw Permalink 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.
-- 初始化数据迁移
-- 合并内容:
-- 1. 轮询系统预置配置(原 000104_polling_config_data.up.sql
-- 2. 历史订单 purchase_role 回填(原 backfill_order_purchase_role.sql
-- 所有操作均幂等ON CONFLICT DO NOTHING / WHERE xxx IS NULL
-- ============================================================
-- 第一部分:轮询系统预置配置
-- ============================================================
-- 新增停机卡轮询配置
-- 停机卡需要持续轮询以检测复机条件(套餐购买、流量重置、实名完成)
-- priority=25 介于 not_real_name(10) 和 real_name(20) 之间
INSERT INTO tb_polling_config (
config_name, card_condition, card_category, carrier_id,
priority, realname_check_interval, carddata_check_interval, package_check_interval, protect_check_interval,
status, description, created_at, updated_at
) VALUES (
'停机卡轮询', 'suspended', NULL, NULL,
25, 3600, 3600, 3600, NULL,
1, '停机卡每小时检查实名/流量/套餐,满足条件时自动复机', NOW(), NOW()
)
ON CONFLICT DO NOTHING;
-- 为已激活在线卡配置添加保护期检查间隔
-- protect_check_interval 由迁移 000102 添加,但存量配置均为 NULL导致 protect 任务从未入队
UPDATE tb_polling_config
SET protect_check_interval = 3600, updated_at = NOW()
WHERE card_condition = 'activated' AND protect_check_interval IS NULL;
-- 同步为停机卡配置添加保护期检查(新增配置天然包含,此处保险更新)
UPDATE tb_polling_config
SET protect_check_interval = 3600, updated_at = NOW()
WHERE card_condition = 'suspended' AND protect_check_interval IS NULL;
-- 将 card_condition='real_name' 的配置迁移到 'activated'
-- getCardCondition 修复后不再返回 real_name只返回 not_real_name/activated/suspended
-- real_name 配置将永远无法匹配,需迁移到 activated
UPDATE tb_polling_config
SET card_condition = 'activated',
description = COALESCE(description, '') || '(原 real_name 条件,已迁移至 activated',
updated_at = NOW()
WHERE card_condition = 'real_name';
-- ============================================================
-- 第二部分:历史订单 purchase_role 回填
-- ============================================================
-- 回填平台代购订单offline + is_purchase_on_behalf = true
-- 将现有平台代购订单标记为 purchased_by_platform
UPDATE tb_order
SET
purchase_role = 'purchased_by_platform',
operator_type = 'platform'
WHERE
payment_method = 'offline'
AND is_purchase_on_behalf = true
AND purchase_role IS NULL;