import type { PoolClient } from 'pg'; /** * Backfill order.shipment_status for rows the 1.0.5 sweep left stranded. * * Migration 1.0.5 collapsed every legacy `pending` / `processing` shipment * row to `status='shipped'`, but did NOT recompute the order-level rollup * column. So orders created before §1 still carry a pre-§1 rollup value even * though their underlying shipments now read `shipped`. * * This migration replays the rollup math in SQL for every order whose current * rollup is NOT already one of the valid post-§1 outputs. Orders reading * `shipped` / `delivered` / `partially_*` / `canceled` are left alone; the * math could disagree with them for unrelated reasons (a manually-canceled * shipment after delivery, fixture data from pre-rollup releases) and silently * downgrading them would lose information the user expects to see. * * Everything else is eligible, which is wider than it looks and deliberately * so. 2.1.x shipped FIVE default order shipment statuses — `pending`, * `processing`, `shipped`, `delivered`, `canceled` — and extensions could * register more. An earlier version of this migration only rewrote * `= 'pending'`, so an order a merchant had marked **Processing** kept that * code while 1.0.5 moved its shipment row to `shipped`. `processing` is not a * valid 2.2 rollup, so the admin rendered those orders as "Unknown" * (Order.resolvers.js falls back to `{name:'Unknown'}`) and they stayed stuck * until something re-triggered the rollup. Matching on "not already valid" * instead of "equals pending" also sweeps up custom legacy codes. * * NULL is treated as `pending` (no items shipped yet) and normalised to a real * value rather than left null. * * The math mirrors `services/shipment/resolveShipmentRollup.ts`: sum * shipment_item qty per phase (canceled shipments contribute zero), apply * the rule priority `all:delivered` → `any:delivered` → `all:shipped` → * `any:shipped` → `all:pending` → default `pending`. * * Hardcoded phase mapping assumes the post-§1 default registry * (`shipped` / `delivered` / `canceled`). Custom extension statuses that * fall through to the `ELSE` branch get treated as the `shipped` phase — * a reasonable default for legacy data. The runtime rollup reads phase * from the registry dynamically and handles custom statuses correctly. * Idempotent. */ declare const _default: (connection: PoolClient) => Promise; export default _default;