20261120000004_exit_billing_factor_range.sql 1.1 KB

1234567891011121314151617181920212223242526
  1. -- 线路出口计费系数:取值 (0, 1],最多两位小数(2026-11-20)。
  2. -- 列名仍用 price_factor;展示名=「计费系数」。承接 20261120000002 的旧 CHECK(仅 > 0)。
  3. UPDATE line_exit_catalog
  4. SET price_factor = LEAST(GREATEST(ROUND(price_factor::numeric, 2), 0.01), 1)
  5. WHERE price_factor IS NULL OR price_factor <= 0 OR price_factor > 1
  6. OR price_factor <> ROUND(price_factor::numeric, 2);
  7. DO $$
  8. BEGIN
  9. IF EXISTS (
  10. SELECT 1 FROM pg_constraint WHERE conname = 'line_exit_catalog_price_factor_positive'
  11. ) THEN
  12. ALTER TABLE line_exit_catalog DROP CONSTRAINT line_exit_catalog_price_factor_positive;
  13. END IF;
  14. IF NOT EXISTS (
  15. SELECT 1 FROM pg_constraint WHERE conname = 'line_exit_catalog_price_factor_range'
  16. ) THEN
  17. ALTER TABLE line_exit_catalog
  18. ADD CONSTRAINT line_exit_catalog_price_factor_range
  19. CHECK (price_factor > 0 AND price_factor <= 1);
  20. END IF;
  21. END $$;
  22. COMMENT ON COLUMN line_exit_catalog.price_factor IS
  23. '计费系数(默认 1,取值 (0, 1],最多两位小数);最终订阅价=档位价×本列,向下舍到分;仍禁止运营商/POP/路由矩阵';