diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index ce59fde436f..4f25e0762c0 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -999,3 +999,4 @@ 20240910021542_populating_locked_price_cents_from_pricing_estimate_for_ms_and_cs_service_items.up.sql 20240917132411_update_provides_ppm_closeout_transportation_offices.up.sql 20240917165710_update_duty_locations_provides_services_counseling.up.sql +20241008132316_consolidate_allowable_weight_in_ppm_shipments.up.sql diff --git a/migrations/app/schema/20241008132316_consolidate_allowable_weight_in_ppm_shipments.up.sql b/migrations/app/schema/20241008132316_consolidate_allowable_weight_in_ppm_shipments.up.sql new file mode 100644 index 00000000000..52c31930de4 --- /dev/null +++ b/migrations/app/schema/20241008132316_consolidate_allowable_weight_in_ppm_shipments.up.sql @@ -0,0 +1,20 @@ +SET statement_timeout = 300000; +SET lock_timeout = 300000; +SET idle_in_transaction_session_timeout = 300000; + +ALTER TABLE ppm_shipments +ADD COLUMN IF NOT EXISTS allowable_weight integer; + +COMMENT on COLUMN ppm_shipments.allowable_weight IS 'Combined allowable weight for all trips.'; + +-- Backfill values from weight_tickets table +UPDATE ppm_shipments +SET allowable_weight = summed_weights.summed_allowable_weight +FROM ( + SELECT ppm_shipment_id, SUM(COALESCE(full_weight, 0) - COALESCE(empty_wight, 0)) AS summed_allowable_weight FROM public.weight_tickets + GROUP BY ppm_shipment_id +) AS summed_weights +WHERE ppm_shipments.id = summed_weights.ppm_shipment_id; + +ALTER TABLE weight_tickets +DROP COLUMN allowable_weight;