From 5777c6fd448c5ed0325dbcfcd586118fcbf871db Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 12 Aug 2024 15:59:49 -0500 Subject: [PATCH 1/5] Add generated columns for fdu and fund name to moped_proj_funding and add down migration SQL --- .../migrations/1723496266685_add_fdu_columns/down.sql | 2 ++ .../migrations/1723496266685_add_fdu_columns/up.sql | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 moped-database/migrations/1723496266685_add_fdu_columns/down.sql create mode 100644 moped-database/migrations/1723496266685_add_fdu_columns/up.sql diff --git a/moped-database/migrations/1723496266685_add_fdu_columns/down.sql b/moped-database/migrations/1723496266685_add_fdu_columns/down.sql new file mode 100644 index 0000000000..c7dd743278 --- /dev/null +++ b/moped-database/migrations/1723496266685_add_fdu_columns/down.sql @@ -0,0 +1,2 @@ +-- Drop generated columns generated columns for fund_dept_unit and fund_name +ALTER TABLE moped_proj_funding DROP COLUMN fund_dept_unit, DROP COLUMN fund_name; diff --git a/moped-database/migrations/1723496266685_add_fdu_columns/up.sql b/moped-database/migrations/1723496266685_add_fdu_columns/up.sql new file mode 100644 index 0000000000..9cc950058f --- /dev/null +++ b/moped-database/migrations/1723496266685_add_fdu_columns/up.sql @@ -0,0 +1,8 @@ +-- Add generated columns for fund_dept_unit and fund_name +ALTER TABLE moped_proj_funding +ADD COLUMN fund_dept_unit text GENERATED ALWAYS AS ( + coalesce(fund ->> 'fund_id', ' ') || ' ' || coalesce(dept_unit ->> 'dept', ' ') || ' ' || coalesce(dept_unit ->> 'unit', ' ') +) STORED, +ADD COLUMN fund_name text GENERATED ALWAYS AS ( + coalesce(fund ->> 'fund_name', ' ') +) STORED; From b66d793596bc529e89e3a16ca84055f24c051ec3 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 12 Aug 2024 16:05:25 -0500 Subject: [PATCH 2/5] Handle when fund or unit is null --- .../migrations/1723496266685_add_fdu_columns/up.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/moped-database/migrations/1723496266685_add_fdu_columns/up.sql b/moped-database/migrations/1723496266685_add_fdu_columns/up.sql index 9cc950058f..638e2eb0e3 100644 --- a/moped-database/migrations/1723496266685_add_fdu_columns/up.sql +++ b/moped-database/migrations/1723496266685_add_fdu_columns/up.sql @@ -1,8 +1,8 @@ -- Add generated columns for fund_dept_unit and fund_name ALTER TABLE moped_proj_funding -ADD COLUMN fund_dept_unit text GENERATED ALWAYS AS ( - coalesce(fund ->> 'fund_id', ' ') || ' ' || coalesce(dept_unit ->> 'dept', ' ') || ' ' || coalesce(dept_unit ->> 'unit', ' ') -) STORED, +ADD COLUMN fund_dept_unit text GENERATED ALWAYS AS (CASE WHEN (fund IS null OR dept_unit IS null) THEN null ELSE + coalesce(fund ->> 'fund_id', ' ') || ' ' || coalesce(dept_unit ->> 'dept', ' ') || ' ' || coalesce(dept_unit ->> 'unit', ' ') +END) STORED, ADD COLUMN fund_name text GENERATED ALWAYS AS ( - coalesce(fund ->> 'fund_name', ' ') + CASE WHEN fund IS null THEN null ELSE coalesce(fund ->> 'fund_name', ' ') END ) STORED; From 6789809a14b971d7a45786930dba399b0203a814 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 12 Aug 2024 16:09:03 -0500 Subject: [PATCH 3/5] Add if exists to down migration; update metadata --- moped-database/metadata/tables.yaml | 42 +++++++++++-------- .../1723496266685_add_fdu_columns/down.sql | 2 +- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/moped-database/metadata/tables.yaml b/moped-database/metadata/tables.yaml index 1f60ea359e..19144f072c 100644 --- a/moped-database/metadata/tables.yaml +++ b/moped-database/metadata/tables.yaml @@ -2556,18 +2556,20 @@ - role: moped-admin permission: columns: + - created_at - created_by_user_id + - dept_unit + - fund + - fund_dept_unit + - fund_name - funding_amount + - funding_description - funding_program_id - funding_source_id - funding_status_id - - project_id - - proj_funding_id - - dept_unit - - fund - - funding_description - - created_at - is_deleted + - proj_funding_id + - project_id - updated_at - updated_by_user_id filter: {} @@ -2575,18 +2577,20 @@ - role: moped-editor permission: columns: + - created_at - created_by_user_id + - dept_unit + - fund + - fund_dept_unit + - fund_name - funding_amount + - funding_description - funding_program_id - funding_source_id - funding_status_id - - project_id - - proj_funding_id - - dept_unit - - fund - - funding_description - - created_at - is_deleted + - proj_funding_id + - project_id - updated_at - updated_by_user_id filter: {} @@ -2594,18 +2598,20 @@ - role: moped-viewer permission: columns: + - created_at - created_by_user_id + - dept_unit + - fund + - fund_dept_unit + - fund_name - funding_amount + - funding_description - funding_program_id - funding_source_id - funding_status_id - - project_id - - proj_funding_id - - dept_unit - - fund - - funding_description - - created_at - is_deleted + - proj_funding_id + - project_id - updated_at - updated_by_user_id filter: {} diff --git a/moped-database/migrations/1723496266685_add_fdu_columns/down.sql b/moped-database/migrations/1723496266685_add_fdu_columns/down.sql index c7dd743278..3c6809abc1 100644 --- a/moped-database/migrations/1723496266685_add_fdu_columns/down.sql +++ b/moped-database/migrations/1723496266685_add_fdu_columns/down.sql @@ -1,2 +1,2 @@ -- Drop generated columns generated columns for fund_dept_unit and fund_name -ALTER TABLE moped_proj_funding DROP COLUMN fund_dept_unit, DROP COLUMN fund_name; +ALTER TABLE moped_proj_funding DROP COLUMN IF EXISTS fund_dept_unit, DROP COLUMN IF EXISTS fund_name; From cf481b50bf88a2718e23aff73b62a90b493a60b9 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 12 Aug 2024 16:49:05 -0500 Subject: [PATCH 4/5] Add Bike Share Station component type --- .../migrations/1723496266685_add_fdu_columns/up.sql | 3 +++ .../1723496266686_add_bike_share_station_comp/down.sql | 2 ++ .../1723496266686_add_bike_share_station_comp/up.sql | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 moped-database/migrations/1723496266686_add_bike_share_station_comp/down.sql create mode 100644 moped-database/migrations/1723496266686_add_bike_share_station_comp/up.sql diff --git a/moped-database/migrations/1723496266685_add_fdu_columns/up.sql b/moped-database/migrations/1723496266685_add_fdu_columns/up.sql index 638e2eb0e3..bbd33248b3 100644 --- a/moped-database/migrations/1723496266685_add_fdu_columns/up.sql +++ b/moped-database/migrations/1723496266685_add_fdu_columns/up.sql @@ -6,3 +6,6 @@ END) STORED, ADD COLUMN fund_name text GENERATED ALWAYS AS ( CASE WHEN fund IS null THEN null ELSE coalesce(fund ->> 'fund_name', ' ') END ) STORED; + +COMMENT ON COLUMN moped_proj_funding.fund_dept_unit IS 'Fund, department, and unit numbers concatenated; null if fund or unit is not populated'; +COMMENT ON COLUMN moped_proj_funding.fund_name IS 'Fund name; null if fund is not populated'; diff --git a/moped-database/migrations/1723496266686_add_bike_share_station_comp/down.sql b/moped-database/migrations/1723496266686_add_bike_share_station_comp/down.sql new file mode 100644 index 0000000000..cc980b7e9e --- /dev/null +++ b/moped-database/migrations/1723496266686_add_bike_share_station_comp/down.sql @@ -0,0 +1,2 @@ +DELETE FROM moped_components +WHERE moped_components.component_name = 'Bike Share Station'; diff --git a/moped-database/migrations/1723496266686_add_bike_share_station_comp/up.sql b/moped-database/migrations/1723496266686_add_bike_share_station_comp/up.sql new file mode 100644 index 0000000000..f5de88de7c --- /dev/null +++ b/moped-database/migrations/1723496266686_add_bike_share_station_comp/up.sql @@ -0,0 +1,4 @@ +INSERT INTO moped_components ( + component_name, line_representation, feature_layer_id +) VALUES +('Bike Share Station', FALSE, 5); From 632fb7a2ad10295be3ce76424e8007c332a59d57 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 14 Aug 2024 13:16:23 -0500 Subject: [PATCH 5/5] Remove bike share migration --- .../1723496266686_add_bike_share_station_comp/down.sql | 2 -- .../1723496266686_add_bike_share_station_comp/up.sql | 4 ---- 2 files changed, 6 deletions(-) delete mode 100644 moped-database/migrations/1723496266686_add_bike_share_station_comp/down.sql delete mode 100644 moped-database/migrations/1723496266686_add_bike_share_station_comp/up.sql diff --git a/moped-database/migrations/1723496266686_add_bike_share_station_comp/down.sql b/moped-database/migrations/1723496266686_add_bike_share_station_comp/down.sql deleted file mode 100644 index cc980b7e9e..0000000000 --- a/moped-database/migrations/1723496266686_add_bike_share_station_comp/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DELETE FROM moped_components -WHERE moped_components.component_name = 'Bike Share Station'; diff --git a/moped-database/migrations/1723496266686_add_bike_share_station_comp/up.sql b/moped-database/migrations/1723496266686_add_bike_share_station_comp/up.sql deleted file mode 100644 index f5de88de7c..0000000000 --- a/moped-database/migrations/1723496266686_add_bike_share_station_comp/up.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO moped_components ( - component_name, line_representation, feature_layer_id -) VALUES -('Bike Share Station', FALSE, 5);