Files
junhong_cmp_fiber/migrations/000227_add_carrier_traffic_threshold.down.sql
break 59b3df868a
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 12m59s
feat(通道流量阈值): AUG26-011 运营商通道流量阈值达量停机与周期复机
2026-09-16 15:54:49 +08:00

37 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.
-- 回滚运营商通道流量阈值停机:删除周期阈值停机锁表与 tb_carrier 的阈值三列,与 up 严格成对。
-- 先删锁表索引与锁表,再删除 tb_carrier 的三个阈值列,顺序与 up 的创建顺序严格倒序。
--
-- 不可逆说明ENG-MIG-001 例外条件):本迁移的 down 会删除 tb_carrier_traffic_threshold_lock 与
-- tb_carrier 的 traffic_threshold_enabled/traffic_threshold_value/traffic_threshold_unit 三列。
-- 已触发的阈值停机事实(锁行)与运营商阈值配置都无法由数据库自身重建,只能依据
-- tb_audit_event 中 carrier_create/carrier_update 的前后值快照与 Integration Log 人工复核,
-- 因此 down 只在上述事实已无留存需求时执行。
--
-- 守卫一:锁表存在任何未软删行时直接阻断回滚,避免静默丢失阈值停机/复机事实与恢复扫描状态。
-- 守卫二:存在任一已配置阈值(启用或已填数值)的运营商时直接阻断回滚,避免静默丢失阈值配置。
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM tb_carrier_traffic_threshold_lock WHERE deleted_at IS NULL LIMIT 1) THEN
RAISE EXCEPTION '存在通道流量阈值周期锁事实,拒绝回滚以避免丢失停机/复机事实与恢复扫描状态';
END IF;
END $$;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM tb_carrier WHERE traffic_threshold_enabled = 1 OR traffic_threshold_value IS NOT NULL LIMIT 1) THEN
RAISE EXCEPTION '存在已配置通道流量阈值的运营商,拒绝回滚以避免丢失阈值配置';
END IF;
END $$;
DROP INDEX IF EXISTS idx_carrier_traffic_threshold_lock_submitted;
DROP INDEX IF EXISTS idx_carrier_traffic_threshold_lock_card;
DROP INDEX IF EXISTS idx_carrier_traffic_threshold_lock_status_period;
DROP TABLE IF EXISTS tb_carrier_traffic_threshold_lock;
ALTER TABLE tb_carrier
DROP COLUMN IF EXISTS traffic_threshold_enabled,
DROP COLUMN IF EXISTS traffic_threshold_value,
DROP COLUMN IF EXISTS traffic_threshold_unit;