Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B-19935 #13165

Merged
merged 12 commits into from
Sep 4, 2024
2 changes: 2 additions & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,8 @@
20240613192433_move_valid_loa_for_tac_col_to_lines_of_accounting_table.up.sql
20240624215947_add_sit_reimburseable_amount.up.sql
20240625144828_add_to_update_type_enum.up.sql
20240628181051_drop_ppm_postal_code_fields.up.sql
20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql
20240716161148_create_boat_shipment_table.up.sql
20240718021218_add_assigned_cols_to_moves.up.sql
20240719192106_add_destination_gbloc_to_orders.up.sql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE ppm_shipments
DROP COLUMN IF EXISTS pickup_postal_code cascade;

ALTER TABLE ppm_shipments
DROP COLUMN IF EXISTS secondary_pickup_postal_code cascade;

ALTER TABLE ppm_shipments
DROP COLUMN IF EXISTS destination_postal_code cascade;

ALTER TABLE ppm_shipments
DROP COLUMN IF EXISTS secondary_destination_postal_code cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- This view still finds the GBLOC for the first shipment of each move. NTS-Release shipments won't have a match,
-- but they are handled in a different spot, so the null value is ok here.
CREATE OR REPLACE VIEW move_to_gbloc AS
SELECT DISTINCT ON (sh.move_id) sh.move_id AS move_id, COALESCE(pctg.gbloc, pctg_ppm.gbloc) AS gbloc
FROM mto_shipments sh
-- try the pickup_address path
LEFT JOIN
(
SELECT a.id address_id, pctg.gbloc
FROM addresses a
JOIN postal_code_to_gblocs pctg ON a.postal_code = pctg.postal_code
) pctg ON pctg.address_id = sh.pickup_address_id
-- try the ppm_shipments path
LEFT JOIN
(
SELECT ppm.shipment_id, pctg.gbloc
FROM ppm_shipments ppm
JOIN addresses ppm_address ON ppm.pickup_postal_address_id = ppm_address.id
JOIN postal_code_to_gblocs pctg ON ppm_address.postal_code = pctg.postal_code
) pctg_ppm ON pctg_ppm.shipment_id = sh.id
WHERE sh.deleted_at IS NULL
ORDER BY sh.move_id, sh.created_at;