fix(12): CR-01 widen partner_cost/partner_cost_total to NUMERIC(14,4) to stop silent precision loss

This commit is contained in:
lorentz 2026-07-11 07:16:38 -04:00
parent dbc0d5a703
commit 591fc5cf10

View file

@ -0,0 +1,14 @@
-- Fix: pax8_order_items.partner_cost / partner_cost_total were declared
-- NUMERIC(12,2) (migration 093), but real PAX8 per-unit partner costs carry
-- 3-4 decimal digits of precision (e.g. cost: 22.176, cost: 0.0182 --
-- live-verified sample values from 12-02-SUMMARY.md, exercised in
-- lib/services/pax8-sync-service.test.ts). Postgres silently rounds values
-- that exceed a column's declared scale rather than rejecting them, so
-- NUMERIC(12,2) was quietly corrupting partner-cost data on every insert
-- (22.176 -> 22.18, 0.0182 -> 0.02). This is the same class of fix as
-- migration 094 (there the column was too narrow in *kind*; here it's too
-- narrow in *scale*). Widen to match quantity's NUMERIC(14,4); existing
-- 2-decimal-scale rows convert losslessly.
ALTER TABLE pax8_order_items ALTER COLUMN partner_cost TYPE NUMERIC(14,4) USING partner_cost::numeric;
ALTER TABLE pax8_order_items ALTER COLUMN partner_cost_total TYPE NUMERIC(14,4) USING partner_cost_total::numeric;