From a19322275d4b5972ba563f35c543a39286c77b01 Mon Sep 17 00:00:00 2001 From: Cory Kleinjan Date: Fri, 28 Jun 2024 14:04:16 -0500 Subject: [PATCH 1/3] postal removal --- migrations/app/migrations_manifest.txt | 2 ++ ...8181051_drop_ppm_postal_code_fields.up.sql | 11 +++++++++ ...te_move_to_gbloc_to_use_ppm_address.up.sql | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 migrations/app/schema/20240628181051_drop_ppm_postal_code_fields.up.sql create mode 100644 migrations/app/schema/20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql diff --git a/migrations/app/migrations_manifest.txt b/migrations/app/migrations_manifest.txt index 229d91d2eae..f5a80fb28ca 100644 --- a/migrations/app/migrations_manifest.txt +++ b/migrations/app/migrations_manifest.txt @@ -957,3 +957,5 @@ 20240606195706_adding_uncapped_request_total.up.sql 20240611185048_drop_unique_constraint_emplid.up.sql 20240613192433_move_valid_loa_for_tac_col_to_lines_of_accounting_table.up.sql +20240628181051_drop_ppm_postal_code_fields.up.sql +20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql diff --git a/migrations/app/schema/20240628181051_drop_ppm_postal_code_fields.up.sql b/migrations/app/schema/20240628181051_drop_ppm_postal_code_fields.up.sql new file mode 100644 index 00000000000..d399bdc3e33 --- /dev/null +++ b/migrations/app/schema/20240628181051_drop_ppm_postal_code_fields.up.sql @@ -0,0 +1,11 @@ +ALTER TABLE ppm_shipments +DROP COLUMN pickup_postal_code cascade; + +ALTER TABLE ppm_shipments +DROP COLUMN secondary_pickup_postal_code cascade; + +ALTER TABLE ppm_shipments +DROP COLUMN destination_postal_code cascade; + +ALTER TABLE ppm_shipments +DROP COLUMN secondary_destination_postal_code cascade; \ No newline at end of file diff --git a/migrations/app/schema/20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql b/migrations/app/schema/20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql new file mode 100644 index 00000000000..87b9d9c48ce --- /dev/null +++ b/migrations/app/schema/20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql @@ -0,0 +1,24 @@ +-- This view still finds the GBLOC for the first shipment of each move. PPM shipments +-- don't have full address information, though, so this looks to the postal code field +-- on PPM shipments to match it to a GBLOC. 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; \ No newline at end of file From ed87ad5c7ee8bd06f49748f3f3550b862593676f Mon Sep 17 00:00:00 2001 From: Cory Kleinjan Date: Sun, 30 Jun 2024 19:07:15 -0500 Subject: [PATCH 2/3] Updating comment --- ...40628185537_update_move_to_gbloc_to_use_ppm_address.up.sql | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/migrations/app/schema/20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql b/migrations/app/schema/20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql index 87b9d9c48ce..646b65f19c4 100644 --- a/migrations/app/schema/20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql +++ b/migrations/app/schema/20240628185537_update_move_to_gbloc_to_use_ppm_address.up.sql @@ -1,6 +1,4 @@ --- This view still finds the GBLOC for the first shipment of each move. PPM shipments --- don't have full address information, though, so this looks to the postal code field --- on PPM shipments to match it to a GBLOC. NTS-Release shipments won't have a match, +-- 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 1236cdd926e9caac9247f7b3d9f9fc0024948126 Mon Sep 17 00:00:00 2001 From: Cory Kleinjan Date: Mon, 1 Jul 2024 14:57:21 -0500 Subject: [PATCH 3/3] Adding IF EXISTS to ppm_shipment postal code drop --- .../20240628181051_drop_ppm_postal_code_fields.up.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/migrations/app/schema/20240628181051_drop_ppm_postal_code_fields.up.sql b/migrations/app/schema/20240628181051_drop_ppm_postal_code_fields.up.sql index d399bdc3e33..0600b5fb126 100644 --- a/migrations/app/schema/20240628181051_drop_ppm_postal_code_fields.up.sql +++ b/migrations/app/schema/20240628181051_drop_ppm_postal_code_fields.up.sql @@ -1,11 +1,11 @@ ALTER TABLE ppm_shipments -DROP COLUMN pickup_postal_code cascade; +DROP COLUMN IF EXISTS pickup_postal_code cascade; ALTER TABLE ppm_shipments -DROP COLUMN secondary_pickup_postal_code cascade; +DROP COLUMN IF EXISTS secondary_pickup_postal_code cascade; ALTER TABLE ppm_shipments -DROP COLUMN destination_postal_code cascade; +DROP COLUMN IF EXISTS destination_postal_code cascade; ALTER TABLE ppm_shipments -DROP COLUMN secondary_destination_postal_code cascade; \ No newline at end of file +DROP COLUMN IF EXISTS secondary_destination_postal_code cascade; \ No newline at end of file