Skip to content

Commit

Permalink
migration to consolidate allowable weight from weight_tickets in ppm_…
Browse files Browse the repository at this point in the history
…shipments
  • Loading branch information
ajlusk committed Oct 8, 2024
1 parent 635507b commit 9a2bfda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 9a2bfda

Please sign in to comment.