-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration to consolidate allowable weight from weight_tickets in ppm_…
…shipments
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
migrations/app/schema/20241008132316_consolidate_allowable_weight_in_ppm_shipments.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |