feat: 归档旧迁移文件,创建初始化数据迁移和重置脚本
This commit is contained in:
8
migrations/000115_init_data.down.sql
Normal file
8
migrations/000115_init_data.down.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
-- 回滚初始化数据
|
||||
-- 删除由 000115_init_data.up.sql 插入的轮询配置行
|
||||
-- purchase_role 回填不需要 rollback(历史数据回填,回滚会破坏数据一致性)
|
||||
|
||||
DELETE FROM tb_polling_config
|
||||
WHERE config_name = '停机卡轮询'
|
||||
AND card_condition = 'suspended'
|
||||
AND description = '停机卡每小时检查实名/流量/套餐,满足条件时自动复机';
|
||||
58
migrations/000115_init_data.up.sql
Normal file
58
migrations/000115_init_data.up.sql
Normal file
@@ -0,0 +1,58 @@
|
||||
-- 初始化数据迁移
|
||||
-- 合并内容:
|
||||
-- 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;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user