From 2636290b3011f8aacf538e93e1faf2706487bc11 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 4 Jun 2024 13:26:25 -0500 Subject: [PATCH 01/27] Add project descriptor and project name w/ descriptor fields to agol view --- .../down.sql | 193 ++++++++++++++++++ .../up.sql | 193 ++++++++++++++++++ 2 files changed, 386 insertions(+) create mode 100644 moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/down.sql create mode 100644 moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql diff --git a/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/down.sql b/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/down.sql new file mode 100644 index 0000000000..d59ef295ba --- /dev/null +++ b/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/down.sql @@ -0,0 +1,193 @@ +DROP VIEW IF EXISTS component_arcgis_online_view; + +CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( + SELECT + mpcwt.project_component_id, + string_agg(mwt.name, ', '::text) AS work_types + FROM moped_proj_component_work_types AS mpcwt + LEFT JOIN moped_work_types AS mwt ON mpcwt.work_type_id = mwt.id + WHERE mpcwt.is_deleted = false + GROUP BY mpcwt.project_component_id +), + +council_districts AS ( + SELECT + features.component_id AS project_component_id, + string_agg(DISTINCT features_council_districts.council_district_id::text, ', '::text) AS council_districts + FROM features_council_districts + LEFT JOIN features ON features_council_districts.feature_id = features.id + WHERE features.is_deleted = false + GROUP BY features.component_id +), + +comp_geography AS ( + SELECT + feature_union.component_id AS project_component_id, + string_agg(DISTINCT feature_union.id::text, ', '::text) AS feature_ids, + st_asgeojson(st_union(array_agg(feature_union.geography)))::json AS geometry, + st_asgeojson(st_union(array_agg(feature_union.line_geography)))::json AS line_geometry, + string_agg(DISTINCT feature_union.signal_id::text, ', '::text) AS signal_ids, + sum(feature_union.length_feet) AS length_feet_total + FROM ( + SELECT + feature_signals.id, + feature_signals.component_id, + feature_signals.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_signals.geography, 7::double precision)::geometry) AS line_geography, + feature_signals.signal_id, + null::integer AS length_feet + FROM feature_signals + WHERE feature_signals.is_deleted = false + UNION ALL + SELECT + feature_street_segments.id, + feature_street_segments.component_id, + feature_street_segments.geography::geometry AS geography, + feature_street_segments.geography::geometry AS line_geography, + null::integer AS signal_id, + feature_street_segments.length_feet + FROM feature_street_segments + WHERE feature_street_segments.is_deleted = false + UNION ALL + SELECT + feature_intersections.id, + feature_intersections.component_id, + feature_intersections.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_intersections.geography, 7::double precision)::geometry) AS line_geography, + null::integer AS signal_id, + null::integer AS length_feet + FROM feature_intersections + WHERE feature_intersections.is_deleted = false + UNION ALL + SELECT + feature_drawn_points.id, + feature_drawn_points.component_id, + feature_drawn_points.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_drawn_points.geography, 7::double precision)::geometry) AS line_geography, + null::integer AS signal_id, + null::integer AS length_feet + FROM feature_drawn_points + WHERE feature_drawn_points.is_deleted = false + UNION ALL + SELECT + feature_drawn_lines.id, + feature_drawn_lines.component_id, + feature_drawn_lines.geography::geometry AS geography, + feature_drawn_lines.geography::geometry AS line_geography, + null::integer AS signal_id, + feature_drawn_lines.length_feet + FROM feature_drawn_lines + WHERE feature_drawn_lines.is_deleted = false + ) AS feature_union + GROUP BY feature_union.component_id +), + +subcomponents AS ( + SELECT + mpcs.project_component_id, + string_agg(ms.subcomponent_name, ', '::text) AS subcomponents + FROM moped_proj_components_subcomponents AS mpcs + LEFT JOIN moped_subcomponents AS ms ON mpcs.subcomponent_id = ms.subcomponent_id + WHERE mpcs.is_deleted = false + GROUP BY mpcs.project_component_id +), + +component_tags AS ( + SELECT + mpct.project_component_id, + string_agg((mct.type || ' - '::text) || mct.name, ', '::text) AS component_tags + FROM moped_proj_component_tags AS mpct + LEFT JOIN moped_component_tags AS mct ON mpct.component_tag_id = mct.id + WHERE mpct.is_deleted = false + GROUP BY mpct.project_component_id +) + +SELECT + mpc.project_id, + comp_geography.project_component_id, + comp_geography.feature_ids, + mpc.component_id, + comp_geography.geometry, + comp_geography.line_geometry, + comp_geography.signal_ids, + council_districts.council_districts, + 'placeholder text'::text AS council_districts_searchable, + NOT coalesce(council_districts.council_districts IS null OR council_districts.council_districts = ''::text, false) AS is_within_city_limits, + comp_geography.length_feet_total, + round(comp_geography.length_feet_total::numeric / 5280::numeric, 2) AS length_miles_total, + mc.component_name, + mc.component_subtype, + mc.component_name_full, + 'placeholder text'::text AS component_categories, + subcomponents.subcomponents AS component_subcomponents, + work_types.work_types AS component_work_types, + component_tags.component_tags, + mpc.description AS component_description, + mpc.interim_project_component_id, + mpc.completion_date, + coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, + '2024-01-01T00:00:00-06:00'::text AS substantial_completion_date_estimated, + mpc.srts_id, + mpc.location_description AS component_location_description, + plv.project_name, + 'placeholder text'::text AS project_name_descriptor, + 'placeholder text'::text AS project_name_with_descriptor, + plv.project_description, + plv.ecapris_subproject_id, + plv.project_website, + plv.updated_at AS project_updated_at, + mpc.phase_id AS component_phase_id, + mph.phase_name AS component_phase_name, + mph.phase_name_simple AS component_phase_name_simple, + current_phase.phase_id AS project_phase_id, + current_phase.phase_name AS project_phase_name, + current_phase.phase_name_simple AS project_phase_name_simple, + coalesce(mph.phase_name, current_phase.phase_name) AS current_phase_name, + coalesce(mph.phase_name_simple, current_phase.phase_name_simple) AS current_phase_name_simple, + plv.project_team_members, + plv.project_sponsor, + plv.project_lead, + plv.public_process_status, + plv.interim_project_id, + plv.project_partners, + plv.task_order_names, + plv.funding_source_name, + plv.type_name, + plv.project_status_update, + plv.project_status_update_date_created, + plv.construction_start_date, + plv.completion_end_date, + plv.project_inspector, + plv.project_designer, + plv.project_tags, + plv.workgroup_contractors, + plv.contract_numbers, + plv.parent_project_id, + plv.parent_project_name, + plv.parent_project_url, + 'placeholder text'::text AS parent_project_name_with_descriptor, + 'placeholder text'::text AS related_project_ids, + 'placeholder text'::text AS related_project_ids_searchable, + plv.knack_project_id AS knack_data_tracker_project_record_id, + plv.project_url, + (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, + plv.project_development_status, + plv.project_development_status_date, + plv.project_development_status_date_calendar_year, + plv.project_development_status_date_calendar_year_month, + plv.project_development_status_date_calendar_year_month_numeric, + plv.project_development_status_date_calendar_year_quarter, + plv.project_development_status_date_fiscal_year, + plv.project_development_status_date_fiscal_year_quarter, + plv.added_by AS project_added_by +FROM moped_proj_components AS mpc +LEFT JOIN comp_geography ON mpc.project_component_id = comp_geography.project_component_id +LEFT JOIN council_districts ON mpc.project_component_id = council_districts.project_component_id +LEFT JOIN subcomponents ON mpc.project_component_id = subcomponents.project_component_id +LEFT JOIN work_types ON mpc.project_component_id = work_types.project_component_id +LEFT JOIN component_tags ON mpc.project_component_id = component_tags.project_component_id +LEFT JOIN project_list_view AS plv ON mpc.project_id = plv.project_id +LEFT JOIN current_phase_view AS current_phase ON mpc.project_id = current_phase.project_id +LEFT JOIN moped_phases AS mph ON mpc.phase_id = mph.phase_id +LEFT JOIN moped_components AS mc ON mpc.component_id = mc.component_id +WHERE mpc.is_deleted = false AND plv.is_deleted = false; diff --git a/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql b/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql new file mode 100644 index 0000000000..d3c52f104c --- /dev/null +++ b/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql @@ -0,0 +1,193 @@ +DROP VIEW IF EXISTS component_arcgis_online_view; + +CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( + SELECT + mpcwt.project_component_id, + string_agg(mwt.name, ', '::text) AS work_types + FROM moped_proj_component_work_types mpcwt + LEFT JOIN moped_work_types mwt ON mpcwt.work_type_id = mwt.id + WHERE mpcwt.is_deleted = false + GROUP BY mpcwt.project_component_id +), + +council_districts AS ( + SELECT + features.component_id AS project_component_id, + string_agg(DISTINCT features_council_districts.council_district_id::text, ', '::text) AS council_districts + FROM features_council_districts + LEFT JOIN features ON features_council_districts.feature_id = features.id + WHERE features.is_deleted = false + GROUP BY features.component_id +), + +comp_geography AS ( + SELECT + feature_union.component_id AS project_component_id, + string_agg(DISTINCT feature_union.id::text, ', '::text) AS feature_ids, + st_asgeojson(st_union(array_agg(feature_union.geography)))::json AS geometry, + st_asgeojson(st_union(array_agg(feature_union.line_geography)))::json AS line_geometry, + string_agg(DISTINCT feature_union.signal_id::text, ', '::text) AS signal_ids, + sum(feature_union.length_feet) AS length_feet_total + FROM ( + SELECT + feature_signals.id, + feature_signals.component_id, + feature_signals.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_signals.geography, 7::double precision)::geometry) AS line_geography, + feature_signals.signal_id, + null::integer AS length_feet + FROM feature_signals + WHERE feature_signals.is_deleted = false + UNION ALL + SELECT + feature_street_segments.id, + feature_street_segments.component_id, + feature_street_segments.geography::geometry AS geography, + feature_street_segments.geography::geometry AS line_geography, + null::integer AS signal_id, + feature_street_segments.length_feet + FROM feature_street_segments + WHERE feature_street_segments.is_deleted = false + UNION ALL + SELECT + feature_intersections.id, + feature_intersections.component_id, + feature_intersections.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_intersections.geography, 7::double precision)::geometry) AS line_geography, + null::integer AS signal_id, + null::integer AS length_feet + FROM feature_intersections + WHERE feature_intersections.is_deleted = false + UNION ALL + SELECT + feature_drawn_points.id, + feature_drawn_points.component_id, + feature_drawn_points.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_drawn_points.geography, 7::double precision)::geometry) AS line_geography, + null::integer AS signal_id, + null::integer AS length_feet + FROM feature_drawn_points + WHERE feature_drawn_points.is_deleted = false + UNION ALL + SELECT + feature_drawn_lines.id, + feature_drawn_lines.component_id, + feature_drawn_lines.geography::geometry AS geography, + feature_drawn_lines.geography::geometry AS line_geography, + null::integer AS signal_id, + feature_drawn_lines.length_feet + FROM feature_drawn_lines + WHERE feature_drawn_lines.is_deleted = false + ) feature_union + GROUP BY feature_union.component_id +), + +subcomponents AS ( + SELECT + mpcs.project_component_id, + string_agg(ms.subcomponent_name, ', '::text) AS subcomponents + FROM moped_proj_components_subcomponents mpcs + LEFT JOIN moped_subcomponents ms ON mpcs.subcomponent_id = ms.subcomponent_id + WHERE mpcs.is_deleted = false + GROUP BY mpcs.project_component_id +), + +component_tags AS ( + SELECT + mpct.project_component_id, + string_agg((mct.type || ' - '::text) || mct.name, ', '::text) AS component_tags + FROM moped_proj_component_tags mpct + LEFT JOIN moped_component_tags mct ON mpct.component_tag_id = mct.id + WHERE mpct.is_deleted = false + GROUP BY mpct.project_component_id +) + +SELECT + mpc.project_id, + comp_geography.project_component_id, + comp_geography.feature_ids, + mpc.component_id, + comp_geography.geometry, + comp_geography.line_geometry, + comp_geography.signal_ids, + council_districts.council_districts, + 'placeholder text'::text AS council_districts_searchable, + NOT coalesce(council_districts.council_districts IS null OR council_districts.council_districts = ''::text, false) AS is_within_city_limits, + comp_geography.length_feet_total, + round(comp_geography.length_feet_total::numeric / 5280::numeric, 2) AS length_miles_total, + mc.component_name, + mc.component_subtype, + mc.component_name_full, + 'placeholder text'::text AS component_categories, + subcomponents.subcomponents AS component_subcomponents, + work_types.work_types AS component_work_types, + component_tags.component_tags, + mpc.description AS component_description, + mpc.interim_project_component_id, + mpc.completion_date, + coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, + '2024-01-01T00:00:00-06:00'::text AS substantial_completion_date_estimated, + mpc.srts_id, + mpc.location_description AS component_location_description, + plv.project_name, + plv.project_name_secondary AS project_name_descriptor, + plv.project_name_full AS project_name_with_descriptor, + plv.project_description, + plv.ecapris_subproject_id, + plv.project_website, + plv.updated_at AS project_updated_at, + mpc.phase_id AS component_phase_id, + mph.phase_name AS component_phase_name, + mph.phase_name_simple AS component_phase_name_simple, + current_phase.phase_id AS project_phase_id, + current_phase.phase_name AS project_phase_name, + current_phase.phase_name_simple AS project_phase_name_simple, + coalesce(mph.phase_name, current_phase.phase_name) AS current_phase_name, + coalesce(mph.phase_name_simple, current_phase.phase_name_simple) AS current_phase_name_simple, + plv.project_team_members, + plv.project_sponsor, + plv.project_lead, + plv.public_process_status, + plv.interim_project_id, + plv.project_partners, + plv.task_order_names, + plv.funding_source_name, + plv.type_name, + plv.project_status_update, + plv.project_status_update_date_created, + plv.construction_start_date, + plv.completion_end_date, + plv.project_inspector, + plv.project_designer, + plv.project_tags, + plv.workgroup_contractors, + plv.contract_numbers, + plv.parent_project_id, + plv.parent_project_name, + plv.parent_project_url, + 'placeholder text'::text AS parent_project_name_with_descriptor, + 'placeholder text'::text AS related_project_ids, + 'placeholder text'::text AS related_project_ids_searchable, + plv.knack_project_id AS knack_data_tracker_project_record_id, + plv.project_url, + (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, + plv.project_development_status, + plv.project_development_status_date, + plv.project_development_status_date_calendar_year, + plv.project_development_status_date_calendar_year_month, + plv.project_development_status_date_calendar_year_month_numeric, + plv.project_development_status_date_calendar_year_quarter, + plv.project_development_status_date_fiscal_year, + plv.project_development_status_date_fiscal_year_quarter, + plv.added_by AS project_added_by +FROM moped_proj_components mpc +LEFT JOIN comp_geography ON mpc.project_component_id = comp_geography.project_component_id +LEFT JOIN council_districts ON mpc.project_component_id = council_districts.project_component_id +LEFT JOIN subcomponents ON mpc.project_component_id = subcomponents.project_component_id +LEFT JOIN work_types ON mpc.project_component_id = work_types.project_component_id +LEFT JOIN component_tags ON mpc.project_component_id = component_tags.project_component_id +LEFT JOIN project_list_view plv ON mpc.project_id = plv.project_id +LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.project_id +LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id +LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id +WHERE mpc.is_deleted = false AND plv.is_deleted = false; From aa46728a894476b3dd9d532c21406a73da5a5ea3 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 4 Jun 2024 13:41:39 -0500 Subject: [PATCH 02/27] Add parent project name with descriptor as parent project name (full) --- .../up.sql | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql b/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql index d3c52f104c..05fb7d4c18 100644 --- a/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql +++ b/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql @@ -4,8 +4,8 @@ CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( SELECT mpcwt.project_component_id, string_agg(mwt.name, ', '::text) AS work_types - FROM moped_proj_component_work_types mpcwt - LEFT JOIN moped_work_types mwt ON mpcwt.work_type_id = mwt.id + FROM moped_proj_component_work_types AS mpcwt + LEFT JOIN moped_work_types AS mwt ON mpcwt.work_type_id = mwt.id WHERE mpcwt.is_deleted = false GROUP BY mpcwt.project_component_id ), @@ -78,7 +78,7 @@ comp_geography AS ( feature_drawn_lines.length_feet FROM feature_drawn_lines WHERE feature_drawn_lines.is_deleted = false - ) feature_union + ) AS feature_union GROUP BY feature_union.component_id ), @@ -86,8 +86,8 @@ subcomponents AS ( SELECT mpcs.project_component_id, string_agg(ms.subcomponent_name, ', '::text) AS subcomponents - FROM moped_proj_components_subcomponents mpcs - LEFT JOIN moped_subcomponents ms ON mpcs.subcomponent_id = ms.subcomponent_id + FROM moped_proj_components_subcomponents AS mpcs + LEFT JOIN moped_subcomponents AS ms ON mpcs.subcomponent_id = ms.subcomponent_id WHERE mpcs.is_deleted = false GROUP BY mpcs.project_component_id ), @@ -96,8 +96,8 @@ component_tags AS ( SELECT mpct.project_component_id, string_agg((mct.type || ' - '::text) || mct.name, ', '::text) AS component_tags - FROM moped_proj_component_tags mpct - LEFT JOIN moped_component_tags mct ON mpct.component_tag_id = mct.id + FROM moped_proj_component_tags AS mpct + LEFT JOIN moped_component_tags AS mct ON mpct.component_tag_id = mct.id WHERE mpct.is_deleted = false GROUP BY mpct.project_component_id ) @@ -165,7 +165,7 @@ SELECT plv.parent_project_id, plv.parent_project_name, plv.parent_project_url, - 'placeholder text'::text AS parent_project_name_with_descriptor, + plv.parent_project_name AS parent_project_name_with_descriptor, 'placeholder text'::text AS related_project_ids, 'placeholder text'::text AS related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, @@ -180,14 +180,14 @@ SELECT plv.project_development_status_date_fiscal_year, plv.project_development_status_date_fiscal_year_quarter, plv.added_by AS project_added_by -FROM moped_proj_components mpc +FROM moped_proj_components AS mpc LEFT JOIN comp_geography ON mpc.project_component_id = comp_geography.project_component_id LEFT JOIN council_districts ON mpc.project_component_id = council_districts.project_component_id LEFT JOIN subcomponents ON mpc.project_component_id = subcomponents.project_component_id LEFT JOIN work_types ON mpc.project_component_id = work_types.project_component_id LEFT JOIN component_tags ON mpc.project_component_id = component_tags.project_component_id -LEFT JOIN project_list_view plv ON mpc.project_id = plv.project_id -LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.project_id -LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id -LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id +LEFT JOIN project_list_view AS plv ON mpc.project_id = plv.project_id +LEFT JOIN current_phase_view AS current_phase ON mpc.project_id = current_phase.project_id +LEFT JOIN moped_phases AS mph ON mpc.phase_id = mph.phase_id +LEFT JOIN moped_components AS mc ON mpc.component_id = mc.component_id WHERE mpc.is_deleted = false AND plv.is_deleted = false; From 81283a5b212c22d6f5c5d3cecd28cf8990ce8786 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 4 Jun 2024 15:50:00 -0500 Subject: [PATCH 03/27] Sort component tags in data dictionary --- moped-editor/src/queries/tableLookups.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/moped-editor/src/queries/tableLookups.js b/moped-editor/src/queries/tableLookups.js index 99017b5152..e2e08b3c68 100644 --- a/moped-editor/src/queries/tableLookups.js +++ b/moped-editor/src/queries/tableLookups.js @@ -58,7 +58,10 @@ export const TABLE_LOOKUPS_QUERY = gql` entity_id entity_name } - moped_component_tags(where: { is_deleted: { _eq: false } }) { + moped_component_tags( + where: { is_deleted: { _eq: false } } + order_by: { type: asc, name: asc } + ) { id type name From 59d6c88d7b68d230cd3c55a9010117626e8d45c7 Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Tue, 4 Jun 2024 20:51:20 +0000 Subject: [PATCH 04/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-descriptor-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moped-database/views/component_arcgis_online_view.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index 10ab07b27e..5baecd7fc4 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -1,4 +1,4 @@ --- Most recent migration: moped-database/migrations/1713896796482_add_full_name_to_list_view/up.sql +-- Most recent migration: moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( SELECT @@ -130,8 +130,8 @@ SELECT mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, - 'placeholder text'::text AS project_name_descriptor, - 'placeholder text'::text AS project_name_with_descriptor, + plv.project_name_secondary AS project_name_descriptor, + plv.project_name_full AS project_name_with_descriptor, plv.project_description, plv.ecapris_subproject_id, plv.project_website, @@ -165,7 +165,7 @@ SELECT plv.parent_project_id, plv.parent_project_name, plv.parent_project_url, - 'placeholder text'::text AS parent_project_name_with_descriptor, + plv.parent_project_name AS parent_project_name_with_descriptor, 'placeholder text'::text AS related_project_ids, 'placeholder text'::text AS related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, From 29a0bb63c894df2f09a37755450f95685245182a Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 13 Jun 2024 16:11:06 -0500 Subject: [PATCH 05/27] Rename descriptor fields to use secondary and full --- moped-database/metadata/tables.yaml | 18 +++++++++--------- .../up.sql | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/moped-database/metadata/tables.yaml b/moped-database/metadata/tables.yaml index ced12ff723..0881d942bf 100644 --- a/moped-database/metadata/tables.yaml +++ b/moped-database/metadata/tables.yaml @@ -44,7 +44,7 @@ - funding_source_name - knack_data_tracker_project_record_id - parent_project_name - - parent_project_name_with_descriptor + - parent_project_name_full - parent_project_url - project_added_by - project_description @@ -52,8 +52,8 @@ - project_inspector - project_lead - project_name - - project_name_descriptor - - project_name_with_descriptor + - project_name_secondary + - project_name_full - project_partners - project_phase_name - project_phase_name_simple @@ -126,7 +126,7 @@ - funding_source_name - knack_data_tracker_project_record_id - parent_project_name - - parent_project_name_with_descriptor + - parent_project_name_full - parent_project_url - project_added_by - project_description @@ -134,8 +134,8 @@ - project_inspector - project_lead - project_name - - project_name_descriptor - - project_name_with_descriptor + - project_name_secondary + - project_name_full - project_partners - project_phase_name - project_phase_name_simple @@ -208,7 +208,7 @@ - funding_source_name - knack_data_tracker_project_record_id - parent_project_name - - parent_project_name_with_descriptor + - parent_project_name_full - parent_project_url - project_added_by - project_description @@ -216,8 +216,8 @@ - project_inspector - project_lead - project_name - - project_name_descriptor - - project_name_with_descriptor + - project_name_secondary + - project_name_full - project_partners - project_phase_name - project_phase_name_simple diff --git a/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql b/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql index 05fb7d4c18..bb28bf63e1 100644 --- a/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql +++ b/moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql @@ -130,8 +130,8 @@ SELECT mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, - plv.project_name_secondary AS project_name_descriptor, - plv.project_name_full AS project_name_with_descriptor, + plv.project_name_secondary AS project_name_secondary, + plv.project_name_full AS project_name_full, plv.project_description, plv.ecapris_subproject_id, plv.project_website, @@ -165,7 +165,7 @@ SELECT plv.parent_project_id, plv.parent_project_name, plv.parent_project_url, - plv.parent_project_name AS parent_project_name_with_descriptor, + plv.parent_project_name AS parent_project_name_full, 'placeholder text'::text AS related_project_ids, 'placeholder text'::text AS related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, From 509f93655f6ebc7acfc1f497b9bdc4737d0ceb09 Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Thu, 13 Jun 2024 21:12:14 +0000 Subject: [PATCH 06/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-descriptor-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moped-database/views/component_arcgis_online_view.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index 5baecd7fc4..688b944d5e 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -130,8 +130,8 @@ SELECT mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, - plv.project_name_secondary AS project_name_descriptor, - plv.project_name_full AS project_name_with_descriptor, + plv.project_name_secondary, + plv.project_name_full, plv.project_description, plv.ecapris_subproject_id, plv.project_website, @@ -165,7 +165,7 @@ SELECT plv.parent_project_id, plv.parent_project_name, plv.parent_project_url, - plv.parent_project_name AS parent_project_name_with_descriptor, + plv.parent_project_name AS parent_project_name_full, 'placeholder text'::text AS related_project_ids, 'placeholder text'::text AS related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, From b4f08166cab68b9ebb506c9b0c6074b2c3a2c3e1 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 13 Jun 2024 16:48:49 -0500 Subject: [PATCH 07/27] Add council districts searchable --- .../down.sql | 193 +++++++++++++++++ .../up.sql | 194 ++++++++++++++++++ 2 files changed, 387 insertions(+) create mode 100644 moped-database/migrations/1718314926409_add_council_districts_searchable/down.sql create mode 100644 moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/down.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/down.sql new file mode 100644 index 0000000000..bb28bf63e1 --- /dev/null +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/down.sql @@ -0,0 +1,193 @@ +DROP VIEW IF EXISTS component_arcgis_online_view; + +CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( + SELECT + mpcwt.project_component_id, + string_agg(mwt.name, ', '::text) AS work_types + FROM moped_proj_component_work_types AS mpcwt + LEFT JOIN moped_work_types AS mwt ON mpcwt.work_type_id = mwt.id + WHERE mpcwt.is_deleted = false + GROUP BY mpcwt.project_component_id +), + +council_districts AS ( + SELECT + features.component_id AS project_component_id, + string_agg(DISTINCT features_council_districts.council_district_id::text, ', '::text) AS council_districts + FROM features_council_districts + LEFT JOIN features ON features_council_districts.feature_id = features.id + WHERE features.is_deleted = false + GROUP BY features.component_id +), + +comp_geography AS ( + SELECT + feature_union.component_id AS project_component_id, + string_agg(DISTINCT feature_union.id::text, ', '::text) AS feature_ids, + st_asgeojson(st_union(array_agg(feature_union.geography)))::json AS geometry, + st_asgeojson(st_union(array_agg(feature_union.line_geography)))::json AS line_geometry, + string_agg(DISTINCT feature_union.signal_id::text, ', '::text) AS signal_ids, + sum(feature_union.length_feet) AS length_feet_total + FROM ( + SELECT + feature_signals.id, + feature_signals.component_id, + feature_signals.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_signals.geography, 7::double precision)::geometry) AS line_geography, + feature_signals.signal_id, + null::integer AS length_feet + FROM feature_signals + WHERE feature_signals.is_deleted = false + UNION ALL + SELECT + feature_street_segments.id, + feature_street_segments.component_id, + feature_street_segments.geography::geometry AS geography, + feature_street_segments.geography::geometry AS line_geography, + null::integer AS signal_id, + feature_street_segments.length_feet + FROM feature_street_segments + WHERE feature_street_segments.is_deleted = false + UNION ALL + SELECT + feature_intersections.id, + feature_intersections.component_id, + feature_intersections.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_intersections.geography, 7::double precision)::geometry) AS line_geography, + null::integer AS signal_id, + null::integer AS length_feet + FROM feature_intersections + WHERE feature_intersections.is_deleted = false + UNION ALL + SELECT + feature_drawn_points.id, + feature_drawn_points.component_id, + feature_drawn_points.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_drawn_points.geography, 7::double precision)::geometry) AS line_geography, + null::integer AS signal_id, + null::integer AS length_feet + FROM feature_drawn_points + WHERE feature_drawn_points.is_deleted = false + UNION ALL + SELECT + feature_drawn_lines.id, + feature_drawn_lines.component_id, + feature_drawn_lines.geography::geometry AS geography, + feature_drawn_lines.geography::geometry AS line_geography, + null::integer AS signal_id, + feature_drawn_lines.length_feet + FROM feature_drawn_lines + WHERE feature_drawn_lines.is_deleted = false + ) AS feature_union + GROUP BY feature_union.component_id +), + +subcomponents AS ( + SELECT + mpcs.project_component_id, + string_agg(ms.subcomponent_name, ', '::text) AS subcomponents + FROM moped_proj_components_subcomponents AS mpcs + LEFT JOIN moped_subcomponents AS ms ON mpcs.subcomponent_id = ms.subcomponent_id + WHERE mpcs.is_deleted = false + GROUP BY mpcs.project_component_id +), + +component_tags AS ( + SELECT + mpct.project_component_id, + string_agg((mct.type || ' - '::text) || mct.name, ', '::text) AS component_tags + FROM moped_proj_component_tags AS mpct + LEFT JOIN moped_component_tags AS mct ON mpct.component_tag_id = mct.id + WHERE mpct.is_deleted = false + GROUP BY mpct.project_component_id +) + +SELECT + mpc.project_id, + comp_geography.project_component_id, + comp_geography.feature_ids, + mpc.component_id, + comp_geography.geometry, + comp_geography.line_geometry, + comp_geography.signal_ids, + council_districts.council_districts, + 'placeholder text'::text AS council_districts_searchable, + NOT coalesce(council_districts.council_districts IS null OR council_districts.council_districts = ''::text, false) AS is_within_city_limits, + comp_geography.length_feet_total, + round(comp_geography.length_feet_total::numeric / 5280::numeric, 2) AS length_miles_total, + mc.component_name, + mc.component_subtype, + mc.component_name_full, + 'placeholder text'::text AS component_categories, + subcomponents.subcomponents AS component_subcomponents, + work_types.work_types AS component_work_types, + component_tags.component_tags, + mpc.description AS component_description, + mpc.interim_project_component_id, + mpc.completion_date, + coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, + '2024-01-01T00:00:00-06:00'::text AS substantial_completion_date_estimated, + mpc.srts_id, + mpc.location_description AS component_location_description, + plv.project_name, + plv.project_name_secondary AS project_name_secondary, + plv.project_name_full AS project_name_full, + plv.project_description, + plv.ecapris_subproject_id, + plv.project_website, + plv.updated_at AS project_updated_at, + mpc.phase_id AS component_phase_id, + mph.phase_name AS component_phase_name, + mph.phase_name_simple AS component_phase_name_simple, + current_phase.phase_id AS project_phase_id, + current_phase.phase_name AS project_phase_name, + current_phase.phase_name_simple AS project_phase_name_simple, + coalesce(mph.phase_name, current_phase.phase_name) AS current_phase_name, + coalesce(mph.phase_name_simple, current_phase.phase_name_simple) AS current_phase_name_simple, + plv.project_team_members, + plv.project_sponsor, + plv.project_lead, + plv.public_process_status, + plv.interim_project_id, + plv.project_partners, + plv.task_order_names, + plv.funding_source_name, + plv.type_name, + plv.project_status_update, + plv.project_status_update_date_created, + plv.construction_start_date, + plv.completion_end_date, + plv.project_inspector, + plv.project_designer, + plv.project_tags, + plv.workgroup_contractors, + plv.contract_numbers, + plv.parent_project_id, + plv.parent_project_name, + plv.parent_project_url, + plv.parent_project_name AS parent_project_name_full, + 'placeholder text'::text AS related_project_ids, + 'placeholder text'::text AS related_project_ids_searchable, + plv.knack_project_id AS knack_data_tracker_project_record_id, + plv.project_url, + (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, + plv.project_development_status, + plv.project_development_status_date, + plv.project_development_status_date_calendar_year, + plv.project_development_status_date_calendar_year_month, + plv.project_development_status_date_calendar_year_month_numeric, + plv.project_development_status_date_calendar_year_quarter, + plv.project_development_status_date_fiscal_year, + plv.project_development_status_date_fiscal_year_quarter, + plv.added_by AS project_added_by +FROM moped_proj_components AS mpc +LEFT JOIN comp_geography ON mpc.project_component_id = comp_geography.project_component_id +LEFT JOIN council_districts ON mpc.project_component_id = council_districts.project_component_id +LEFT JOIN subcomponents ON mpc.project_component_id = subcomponents.project_component_id +LEFT JOIN work_types ON mpc.project_component_id = work_types.project_component_id +LEFT JOIN component_tags ON mpc.project_component_id = component_tags.project_component_id +LEFT JOIN project_list_view AS plv ON mpc.project_id = plv.project_id +LEFT JOIN current_phase_view AS current_phase ON mpc.project_id = current_phase.project_id +LEFT JOIN moped_phases AS mph ON mpc.phase_id = mph.phase_id +LEFT JOIN moped_components AS mc ON mpc.component_id = mc.component_id +WHERE mpc.is_deleted = false AND plv.is_deleted = false; diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql new file mode 100644 index 0000000000..f92e0e544c --- /dev/null +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -0,0 +1,194 @@ +DROP VIEW IF EXISTS component_arcgis_online_view; + +CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( + SELECT + mpcwt.project_component_id, + string_agg(mwt.name, ', '::text) AS work_types + FROM moped_proj_component_work_types mpcwt + LEFT JOIN moped_work_types mwt ON mpcwt.work_type_id = mwt.id + WHERE mpcwt.is_deleted = false + GROUP BY mpcwt.project_component_id +), + +council_districts AS ( + SELECT + features.component_id AS project_component_id, + string_agg(DISTINCT features_council_districts.council_district_id::text, ', '::text) AS council_districts, + string_agg(DISTINCT lpad(features_council_districts.council_district_id::text, 2, '0'), ', '::text) AS council_districts_searchable + FROM features_council_districts + LEFT JOIN features ON features_council_districts.feature_id = features.id + WHERE features.is_deleted = false + GROUP BY features.component_id +), + +comp_geography AS ( + SELECT + feature_union.component_id AS project_component_id, + string_agg(DISTINCT feature_union.id::text, ', '::text) AS feature_ids, + st_asgeojson(st_union(array_agg(feature_union.geography)))::json AS geometry, + st_asgeojson(st_union(array_agg(feature_union.line_geography)))::json AS line_geometry, + string_agg(DISTINCT feature_union.signal_id::text, ', '::text) AS signal_ids, + sum(feature_union.length_feet) AS length_feet_total + FROM ( + SELECT + feature_signals.id, + feature_signals.component_id, + feature_signals.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_signals.geography, 7::double precision)::geometry) AS line_geography, + feature_signals.signal_id, + null::integer AS length_feet + FROM feature_signals + WHERE feature_signals.is_deleted = false + UNION ALL + SELECT + feature_street_segments.id, + feature_street_segments.component_id, + feature_street_segments.geography::geometry AS geography, + feature_street_segments.geography::geometry AS line_geography, + null::integer AS signal_id, + feature_street_segments.length_feet + FROM feature_street_segments + WHERE feature_street_segments.is_deleted = false + UNION ALL + SELECT + feature_intersections.id, + feature_intersections.component_id, + feature_intersections.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_intersections.geography, 7::double precision)::geometry) AS line_geography, + null::integer AS signal_id, + null::integer AS length_feet + FROM feature_intersections + WHERE feature_intersections.is_deleted = false + UNION ALL + SELECT + feature_drawn_points.id, + feature_drawn_points.component_id, + feature_drawn_points.geography::geometry AS geography, + st_exteriorring(st_buffer(feature_drawn_points.geography, 7::double precision)::geometry) AS line_geography, + null::integer AS signal_id, + null::integer AS length_feet + FROM feature_drawn_points + WHERE feature_drawn_points.is_deleted = false + UNION ALL + SELECT + feature_drawn_lines.id, + feature_drawn_lines.component_id, + feature_drawn_lines.geography::geometry AS geography, + feature_drawn_lines.geography::geometry AS line_geography, + null::integer AS signal_id, + feature_drawn_lines.length_feet + FROM feature_drawn_lines + WHERE feature_drawn_lines.is_deleted = false + ) feature_union + GROUP BY feature_union.component_id +), + +subcomponents AS ( + SELECT + mpcs.project_component_id, + string_agg(ms.subcomponent_name, ', '::text) AS subcomponents + FROM moped_proj_components_subcomponents mpcs + LEFT JOIN moped_subcomponents ms ON mpcs.subcomponent_id = ms.subcomponent_id + WHERE mpcs.is_deleted = false + GROUP BY mpcs.project_component_id +), + +component_tags AS ( + SELECT + mpct.project_component_id, + string_agg((mct.type || ' - '::text) || mct.name, ', '::text) AS component_tags + FROM moped_proj_component_tags mpct + LEFT JOIN moped_component_tags mct ON mpct.component_tag_id = mct.id + WHERE mpct.is_deleted = false + GROUP BY mpct.project_component_id +) + +SELECT + mpc.project_id, + comp_geography.project_component_id, + comp_geography.feature_ids, + mpc.component_id, + comp_geography.geometry, + comp_geography.line_geometry, + comp_geography.signal_ids, + council_districts.council_districts, + council_districts.council_districts_searchable, + NOT coalesce(council_districts.council_districts IS null OR council_districts.council_districts = ''::text, false) AS is_within_city_limits, + comp_geography.length_feet_total, + round(comp_geography.length_feet_total::numeric / 5280::numeric, 2) AS length_miles_total, + mc.component_name, + mc.component_subtype, + mc.component_name_full, + 'placeholder text'::text AS component_categories, + subcomponents.subcomponents AS component_subcomponents, + work_types.work_types AS component_work_types, + component_tags.component_tags, + mpc.description AS component_description, + mpc.interim_project_component_id, + mpc.completion_date, + coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, + '2024-01-01T00:00:00-06:00'::text AS substantial_completion_date_estimated, + mpc.srts_id, + mpc.location_description AS component_location_description, + plv.project_name, + plv.project_name_secondary, + plv.project_name_full, + plv.project_description, + plv.ecapris_subproject_id, + plv.project_website, + plv.updated_at AS project_updated_at, + mpc.phase_id AS component_phase_id, + mph.phase_name AS component_phase_name, + mph.phase_name_simple AS component_phase_name_simple, + current_phase.phase_id AS project_phase_id, + current_phase.phase_name AS project_phase_name, + current_phase.phase_name_simple AS project_phase_name_simple, + coalesce(mph.phase_name, current_phase.phase_name) AS current_phase_name, + coalesce(mph.phase_name_simple, current_phase.phase_name_simple) AS current_phase_name_simple, + plv.project_team_members, + plv.project_sponsor, + plv.project_lead, + plv.public_process_status, + plv.interim_project_id, + plv.project_partners, + plv.task_order_names, + plv.funding_source_name, + plv.type_name, + plv.project_status_update, + plv.project_status_update_date_created, + plv.construction_start_date, + plv.completion_end_date, + plv.project_inspector, + plv.project_designer, + plv.project_tags, + plv.workgroup_contractors, + plv.contract_numbers, + plv.parent_project_id, + plv.parent_project_name, + plv.parent_project_url, + plv.parent_project_name AS parent_project_name_full, + 'placeholder text'::text AS related_project_ids, + 'placeholder text'::text AS related_project_ids_searchable, + plv.knack_project_id AS knack_data_tracker_project_record_id, + plv.project_url, + (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, + plv.project_development_status, + plv.project_development_status_date, + plv.project_development_status_date_calendar_year, + plv.project_development_status_date_calendar_year_month, + plv.project_development_status_date_calendar_year_month_numeric, + plv.project_development_status_date_calendar_year_quarter, + plv.project_development_status_date_fiscal_year, + plv.project_development_status_date_fiscal_year_quarter, + plv.added_by AS project_added_by +FROM moped_proj_components mpc +LEFT JOIN comp_geography ON mpc.project_component_id = comp_geography.project_component_id +LEFT JOIN council_districts ON mpc.project_component_id = council_districts.project_component_id +LEFT JOIN subcomponents ON mpc.project_component_id = subcomponents.project_component_id +LEFT JOIN work_types ON mpc.project_component_id = work_types.project_component_id +LEFT JOIN component_tags ON mpc.project_component_id = component_tags.project_component_id +LEFT JOIN project_list_view plv ON mpc.project_id = plv.project_id +LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.project_id +LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id +LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id +WHERE mpc.is_deleted = false AND plv.is_deleted = false; From 46c024199df9b0a9853e8a8e20eb088636648d3a Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 13 Jun 2024 17:19:35 -0500 Subject: [PATCH 08/27] Add related project ids and searchable related project ids --- .../up.sql | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index f92e0e544c..12d3657d2c 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -103,6 +103,17 @@ component_tags AS ( GROUP BY mpct.project_component_id ) +related_projects AS ( + SELECT + pmp.project_id, + string_agg(cmp.project_id::text, ', '::text) AS related_project_ids, + string_agg(DISTINCT lpad(cmp.project_id::text, 2, '0'), ', '::text) AS related_project_ids_searchable + FROM moped_project pmp + LEFT JOIN moped_project cmp ON pmp.project_id = cmp.parent_project_id + GROUP BY pmp.project_id +) + + SELECT mpc.project_id, comp_geography.project_component_id, @@ -167,8 +178,8 @@ SELECT plv.parent_project_name, plv.parent_project_url, plv.parent_project_name AS parent_project_name_full, - 'placeholder text'::text AS related_project_ids, - 'placeholder text'::text AS related_project_ids_searchable, + related_projects.related_project_ids AS related_project_ids, + related_projects.related_project_ids_searchable AS related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, plv.project_url, (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, @@ -191,4 +202,5 @@ LEFT JOIN project_list_view plv ON mpc.project_id = plv.project_id LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.project_id LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id +LEFT JOIN related_projects rp ON mpc.project_id = rp.project_id WHERE mpc.is_deleted = false AND plv.is_deleted = false; From 4ec7f6c388c70848b17dc1712da06358d6747791 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 13 Jun 2024 17:31:57 -0500 Subject: [PATCH 09/27] Fix related projects reference and missing comma --- .../up.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index 12d3657d2c..62213bdb21 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -101,15 +101,15 @@ component_tags AS ( LEFT JOIN moped_component_tags mct ON mpct.component_tag_id = mct.id WHERE mpct.is_deleted = false GROUP BY mpct.project_component_id -) +), related_projects AS ( SELECT pmp.project_id, - string_agg(cmp.project_id::text, ', '::text) AS related_project_ids, - string_agg(DISTINCT lpad(cmp.project_id::text, 2, '0'), ', '::text) AS related_project_ids_searchable - FROM moped_project pmp - LEFT JOIN moped_project cmp ON pmp.project_id = cmp.parent_project_id + string_agg(cmp.project_id::text, ', '::text) AS related_project_ids, + string_agg(lpad(cmp.project_id::text, 6, '0'), ', '::text) AS related_project_ids_searchable + FROM moped_project AS pmp + LEFT JOIN moped_project AS cmp ON pmp.project_id = cmp.parent_project_id GROUP BY pmp.project_id ) @@ -178,8 +178,8 @@ SELECT plv.parent_project_name, plv.parent_project_url, plv.parent_project_name AS parent_project_name_full, - related_projects.related_project_ids AS related_project_ids, - related_projects.related_project_ids_searchable AS related_project_ids_searchable, + rp.related_project_ids AS related_project_ids, + rp.related_project_ids_searchable AS related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, plv.project_url, (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, @@ -202,5 +202,5 @@ LEFT JOIN project_list_view plv ON mpc.project_id = plv.project_id LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.project_id LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id -LEFT JOIN related_projects rp ON mpc.project_id = rp.project_id +LEFT JOIN related_projects AS rp ON mpc.project_id = rp.project_id WHERE mpc.is_deleted = false AND plv.is_deleted = false; From 81f8fb6cdd140813589fc95f797b427a8aa4cb82 Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Thu, 13 Jun 2024 22:33:01 +0000 Subject: [PATCH 10/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-other-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/component_arcgis_online_view.sql | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index 688b944d5e..46fee66892 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -1,4 +1,4 @@ --- Most recent migration: moped-database/migrations/1717525278049_add_proj_descriptor_plv_cols/up.sql +-- Most recent migration: moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( SELECT @@ -13,7 +13,8 @@ CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( council_districts AS ( SELECT features.component_id AS project_component_id, - string_agg(DISTINCT features_council_districts.council_district_id::text, ', '::text) AS council_districts + string_agg(DISTINCT features_council_districts.council_district_id::text, ', '::text) AS council_districts, + string_agg(DISTINCT lpad(features_council_districts.council_district_id::text, 2, '0'::text), ', '::text) AS council_districts_searchable FROM features_council_districts LEFT JOIN features ON features_council_districts.feature_id = features.id WHERE features.is_deleted = false @@ -100,6 +101,16 @@ component_tags AS ( LEFT JOIN moped_component_tags mct ON mpct.component_tag_id = mct.id WHERE mpct.is_deleted = false GROUP BY mpct.project_component_id +), + +related_projects AS ( + SELECT + pmp.project_id, + string_agg(cmp.project_id::text, ', '::text) AS related_project_ids, + string_agg(lpad(cmp.project_id::text, 6, '0'::text), ', '::text) AS related_project_ids_searchable + FROM moped_project pmp + LEFT JOIN moped_project cmp ON pmp.project_id = cmp.parent_project_id + GROUP BY pmp.project_id ) SELECT @@ -111,7 +122,7 @@ SELECT comp_geography.line_geometry, comp_geography.signal_ids, council_districts.council_districts, - 'placeholder text'::text AS council_districts_searchable, + council_districts.council_districts_searchable, NOT coalesce(council_districts.council_districts IS null OR council_districts.council_districts = ''::text, false) AS is_within_city_limits, comp_geography.length_feet_total, round(comp_geography.length_feet_total::numeric / 5280::numeric, 2) AS length_miles_total, @@ -166,8 +177,8 @@ SELECT plv.parent_project_name, plv.parent_project_url, plv.parent_project_name AS parent_project_name_full, - 'placeholder text'::text AS related_project_ids, - 'placeholder text'::text AS related_project_ids_searchable, + rp.related_project_ids, + rp.related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, plv.project_url, (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, @@ -190,4 +201,5 @@ LEFT JOIN project_list_view plv ON mpc.project_id = plv.project_id LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.project_id LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id +LEFT JOIN related_projects rp ON mpc.project_id = rp.project_id WHERE mpc.is_deleted = false AND plv.is_deleted = false; From 6495248bfea45c9ad67ff617c01e05bbc7975bf1 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 14 Jun 2024 17:32:50 -0500 Subject: [PATCH 11/27] Add substantial_completion_date_estimated subquery and use min_phase_date column --- .../up.sql | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index 62213bdb21..dc4c267769 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -4,8 +4,8 @@ CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( SELECT mpcwt.project_component_id, string_agg(mwt.name, ', '::text) AS work_types - FROM moped_proj_component_work_types mpcwt - LEFT JOIN moped_work_types mwt ON mpcwt.work_type_id = mwt.id + FROM moped_proj_component_work_types AS mpcwt + LEFT JOIN moped_work_types AS mwt ON mpcwt.work_type_id = mwt.id WHERE mpcwt.is_deleted = false GROUP BY mpcwt.project_component_id ), @@ -79,7 +79,7 @@ comp_geography AS ( feature_drawn_lines.length_feet FROM feature_drawn_lines WHERE feature_drawn_lines.is_deleted = false - ) feature_union + ) AS feature_union GROUP BY feature_union.component_id ), @@ -87,8 +87,8 @@ subcomponents AS ( SELECT mpcs.project_component_id, string_agg(ms.subcomponent_name, ', '::text) AS subcomponents - FROM moped_proj_components_subcomponents mpcs - LEFT JOIN moped_subcomponents ms ON mpcs.subcomponent_id = ms.subcomponent_id + FROM moped_proj_components_subcomponents AS mpcs + LEFT JOIN moped_subcomponents AS ms ON mpcs.subcomponent_id = ms.subcomponent_id WHERE mpcs.is_deleted = false GROUP BY mpcs.project_component_id ), @@ -97,8 +97,8 @@ component_tags AS ( SELECT mpct.project_component_id, string_agg((mct.type || ' - '::text) || mct.name, ', '::text) AS component_tags - FROM moped_proj_component_tags mpct - LEFT JOIN moped_component_tags mct ON mpct.component_tag_id = mct.id + FROM moped_proj_component_tags AS mpct + LEFT JOIN moped_component_tags AS mct ON mpct.component_tag_id = mct.id WHERE mpct.is_deleted = false GROUP BY mpct.project_component_id ), @@ -111,7 +111,28 @@ related_projects AS ( FROM moped_project AS pmp LEFT JOIN moped_project AS cmp ON pmp.project_id = cmp.parent_project_id GROUP BY pmp.project_id -) +), + +-- substantial_completion_date_estimated +-- Derived from the earliest moped_proj_phases phase_start or phase_end where the date is estimated and the phase name is complete or post_construction IF substantial_completion_date is null +-- from project_list_view + +min_phase_dates AS WITH min_dates AS ( + (SELECT + mpp.project_id, + min(mpp.phase_start) as min_phase_start, + min(mpp.phase_end) as min_phase_end + FROM + moped_proj_phases mpp + LEFT JOIN moped_phases mp ON mp.phase_id = mpp.phase_id + WHERE + mpp.is_phase_end_confirmed = FALSE + AND mpp.is_phase_start_confirmed = FALSE + AND phase_start IS NOT NULL + AND mpp.is_deleted = FALSE + AND mp.phase_name_simple = 'Complete'::text + GROUP BY mpp.project_id) + SELECT min_dates.project_id, LEAST(min_dates.min_phase_start, min_dates.min_phase_end) AS min_phase_date FROM min_dates) SELECT @@ -138,7 +159,7 @@ SELECT mpc.interim_project_component_id, mpc.completion_date, coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, - '2024-01-01T00:00:00-06:00'::text AS substantial_completion_date_estimated, + coalesce(substantial_completion_date, mpd.min_phase_date) AS substantial_completion_date_estimated, mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, @@ -192,15 +213,16 @@ SELECT plv.project_development_status_date_fiscal_year, plv.project_development_status_date_fiscal_year_quarter, plv.added_by AS project_added_by -FROM moped_proj_components mpc +FROM moped_proj_components AS mpc LEFT JOIN comp_geography ON mpc.project_component_id = comp_geography.project_component_id LEFT JOIN council_districts ON mpc.project_component_id = council_districts.project_component_id LEFT JOIN subcomponents ON mpc.project_component_id = subcomponents.project_component_id LEFT JOIN work_types ON mpc.project_component_id = work_types.project_component_id LEFT JOIN component_tags ON mpc.project_component_id = component_tags.project_component_id -LEFT JOIN project_list_view plv ON mpc.project_id = plv.project_id -LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.project_id -LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id -LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id +LEFT JOIN project_list_view AS plv ON mpc.project_id = plv.project_id +LEFT JOIN current_phase_view AS current_phase ON mpc.project_id = current_phase.project_id +LEFT JOIN moped_phases AS mph ON mpc.phase_id = mph.phase_id +LEFT JOIN moped_components AS mc ON mpc.component_id = mc.component_id LEFT JOIN related_projects AS rp ON mpc.project_id = rp.project_id +LEFT JOIN min_phase_dates AS mpd ON mpc.project_id = mpd.project_id WHERE mpc.is_deleted = false AND plv.is_deleted = false; From 6f81678349baeacb360eb0a2dccc6d60283f8abb Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 14 Jun 2024 17:35:29 -0500 Subject: [PATCH 12/27] Remove comments and fix typo --- .../up.sql | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index dc4c267769..533c85da5c 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -113,26 +113,34 @@ related_projects AS ( GROUP BY pmp.project_id ), --- substantial_completion_date_estimated --- Derived from the earliest moped_proj_phases phase_start or phase_end where the date is estimated and the phase name is complete or post_construction IF substantial_completion_date is null --- from project_list_view +min_phase_dates AS ( + WITH min_dates AS ( + SELECT + mpp.project_id, + min(mpp.phase_start) AS min_phase_start, + min(mpp.phase_end) AS min_phase_end + FROM + moped_proj_phases AS mpp + LEFT JOIN moped_phases AS mp ON mpp.phase_id = mp.phase_id + WHERE + mpp.is_phase_end_confirmed = false + AND mpp.is_phase_start_confirmed = false + AND phase_start IS NOT null + AND mpp.is_deleted = false + AND mp.phase_name_simple = 'Complete'::text + GROUP BY + mpp.project_id + ) -min_phase_dates AS WITH min_dates AS ( - (SELECT - mpp.project_id, - min(mpp.phase_start) as min_phase_start, - min(mpp.phase_end) as min_phase_end + SELECT + min_dates.project_id, + least( + min_dates.min_phase_start, + min_dates.min_phase_end + ) AS min_phase_date FROM - moped_proj_phases mpp - LEFT JOIN moped_phases mp ON mp.phase_id = mpp.phase_id - WHERE - mpp.is_phase_end_confirmed = FALSE - AND mpp.is_phase_start_confirmed = FALSE - AND phase_start IS NOT NULL - AND mpp.is_deleted = FALSE - AND mp.phase_name_simple = 'Complete'::text - GROUP BY mpp.project_id) - SELECT min_dates.project_id, LEAST(min_dates.min_phase_start, min_dates.min_phase_end) AS min_phase_date FROM min_dates) + min_dates +) SELECT From 169c19f56970612a0eb56c81f4dc44d79b97127a Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Fri, 14 Jun 2024 22:36:33 +0000 Subject: [PATCH 13/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-other-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/component_arcgis_online_view.sql | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index 46fee66892..bb4022fcb3 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -111,6 +111,24 @@ related_projects AS ( FROM moped_project pmp LEFT JOIN moped_project cmp ON pmp.project_id = cmp.parent_project_id GROUP BY pmp.project_id +), + +min_phase_dates AS ( + WITH min_dates AS ( + SELECT + mpp.project_id, + min(mpp.phase_start) AS min_phase_start, + min(mpp.phase_end) AS min_phase_end + FROM moped_proj_phases mpp + LEFT JOIN moped_phases mp ON mpp.phase_id = mp.phase_id + WHERE mpp.is_phase_end_confirmed = false AND mpp.is_phase_start_confirmed = false AND mpp.phase_start IS NOT null AND mpp.is_deleted = false AND mp.phase_name_simple = 'Complete'::text + GROUP BY mpp.project_id + ) + + SELECT + min_dates.project_id, + least(min_dates.min_phase_start, min_dates.min_phase_end) AS min_phase_date + FROM min_dates ) SELECT @@ -137,7 +155,7 @@ SELECT mpc.interim_project_component_id, mpc.completion_date, coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, - '2024-01-01T00:00:00-06:00'::text AS substantial_completion_date_estimated, + coalesce(plv.substantial_completion_date, mpd.min_phase_date) AS substantial_completion_date_estimated, mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, @@ -202,4 +220,5 @@ LEFT JOIN current_phase_view current_phase ON mpc.project_id = current_phase.pro LEFT JOIN moped_phases mph ON mpc.phase_id = mph.phase_id LEFT JOIN moped_components mc ON mpc.component_id = mc.component_id LEFT JOIN related_projects rp ON mpc.project_id = rp.project_id +LEFT JOIN min_phase_dates mpd ON mpc.project_id = mpd.project_id WHERE mpc.is_deleted = false AND plv.is_deleted = false; From 9761c7bb959a4e311bb7b5cf0904ee4a37f7fe93 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 14 Jun 2024 17:49:39 -0500 Subject: [PATCH 14/27] Add case statement to null estimated date when substantial_completion_date is not null --- .../1718314926409_add_council_districts_searchable/up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index 533c85da5c..7742c868c8 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -167,7 +167,7 @@ SELECT mpc.interim_project_component_id, mpc.completion_date, coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, - coalesce(substantial_completion_date, mpd.min_phase_date) AS substantial_completion_date_estimated, + CASE WHEN substantial_completion_date IS NOT null THEN null ELSE mpd.min_phase_date END AS substantial_completion_date_estimated, mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, From c597f463b267687988a2c91434df5c2767bda19b Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Fri, 14 Jun 2024 22:51:03 +0000 Subject: [PATCH 15/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-other-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moped-database/views/component_arcgis_online_view.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index bb4022fcb3..c4b46669d4 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -155,7 +155,10 @@ SELECT mpc.interim_project_component_id, mpc.completion_date, coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, - coalesce(plv.substantial_completion_date, mpd.min_phase_date) AS substantial_completion_date_estimated, + CASE + WHEN plv.substantial_completion_date IS NOT null THEN null::timestamp with time zone + ELSE mpd.min_phase_date + END AS substantial_completion_date_estimated, mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, From 7bc25d898d12c1de681c820c47159012fe2dd1ea Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 17 Jun 2024 16:20:59 -0500 Subject: [PATCH 16/27] Update column names in arcgis etl script --- moped-etl/arcgis/settings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moped-etl/arcgis/settings.py b/moped-etl/arcgis/settings.py index 03825f4ebe..ecb1bb23cf 100644 --- a/moped-etl/arcgis/settings.py +++ b/moped-etl/arcgis/settings.py @@ -40,7 +40,7 @@ line_geometry parent_project_id parent_project_name - parent_project_name_with_descriptor + parent_project_name_full parent_project_url project_added_by project_component_id @@ -58,8 +58,8 @@ project_inspector project_lead project_name - project_name_descriptor - project_name_with_descriptor + project_name_secondary + project_name_full project_partners project_phase_id project_phase_name From e8985a5cfe845774a20ee6e24e39944ce9ab64c8 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 17 Jun 2024 16:28:35 -0500 Subject: [PATCH 17/27] Pad with 5 digits as specified in the doc sheet --- .../1718314926409_add_council_districts_searchable/up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index 7742c868c8..606fb30100 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -107,7 +107,7 @@ related_projects AS ( SELECT pmp.project_id, string_agg(cmp.project_id::text, ', '::text) AS related_project_ids, - string_agg(lpad(cmp.project_id::text, 6, '0'), ', '::text) AS related_project_ids_searchable + string_agg(lpad(cmp.project_id::text, 5, '0'), ', '::text) AS related_project_ids_searchable FROM moped_project AS pmp LEFT JOIN moped_project AS cmp ON pmp.project_id = cmp.parent_project_id GROUP BY pmp.project_id From 6d21b2c4e73279dea67b22bf09ca80f050046466 Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Mon, 17 Jun 2024 21:29:54 +0000 Subject: [PATCH 18/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-other-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moped-database/views/component_arcgis_online_view.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index c4b46669d4..f33a7bbf12 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -107,7 +107,7 @@ related_projects AS ( SELECT pmp.project_id, string_agg(cmp.project_id::text, ', '::text) AS related_project_ids, - string_agg(lpad(cmp.project_id::text, 6, '0'::text), ', '::text) AS related_project_ids_searchable + string_agg(lpad(cmp.project_id::text, 5, '0'::text), ', '::text) AS related_project_ids_searchable FROM moped_project pmp LEFT JOIN moped_project cmp ON pmp.project_id = cmp.parent_project_id GROUP BY pmp.project_id From bccffada46a57d2e5f55c23bb8a9169bcc93825a Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 17 Jun 2024 16:56:24 -0500 Subject: [PATCH 19/27] Add parent project to the related project ids list --- .../1718314926409_add_council_districts_searchable/up.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index 606fb30100..e9105da65d 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -106,8 +106,8 @@ component_tags AS ( related_projects AS ( SELECT pmp.project_id, - string_agg(cmp.project_id::text, ', '::text) AS related_project_ids, - string_agg(lpad(cmp.project_id::text, 5, '0'), ', '::text) AS related_project_ids_searchable + concat_ws(', ', pmp.project_id, string_agg(cmp.project_id::text, ', '::text)) AS related_project_ids_with_self, + concat_ws(', ', lpad(pmp.project_id::text, 5, '0'), string_agg(lpad(cmp.project_id::text, 5, '0'), ', '::text)) AS related_project_ids_searchable_with_self FROM moped_project AS pmp LEFT JOIN moped_project AS cmp ON pmp.project_id = cmp.parent_project_id GROUP BY pmp.project_id @@ -207,8 +207,8 @@ SELECT plv.parent_project_name, plv.parent_project_url, plv.parent_project_name AS parent_project_name_full, - rp.related_project_ids AS related_project_ids, - rp.related_project_ids_searchable AS related_project_ids_searchable, + rp.related_project_ids_with_self AS related_project_ids, + rp.related_project_ids_searchable_with_self AS related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, plv.project_url, (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, From 70d5230a9c6c3c8a63b3dbba2cc6e74748bd2d7a Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Mon, 17 Jun 2024 21:57:24 +0000 Subject: [PATCH 20/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-other-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moped-database/views/component_arcgis_online_view.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index f33a7bbf12..969bc1457a 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -106,8 +106,8 @@ component_tags AS ( related_projects AS ( SELECT pmp.project_id, - string_agg(cmp.project_id::text, ', '::text) AS related_project_ids, - string_agg(lpad(cmp.project_id::text, 5, '0'::text), ', '::text) AS related_project_ids_searchable + concat_ws(', '::text, pmp.project_id, string_agg(cmp.project_id::text, ', '::text)) AS related_project_ids_with_self, + concat_ws(', '::text, lpad(pmp.project_id::text, 5, '0'::text), string_agg(lpad(cmp.project_id::text, 5, '0'::text), ', '::text)) AS related_project_ids_searchable_with_self FROM moped_project pmp LEFT JOIN moped_project cmp ON pmp.project_id = cmp.parent_project_id GROUP BY pmp.project_id @@ -198,8 +198,8 @@ SELECT plv.parent_project_name, plv.parent_project_url, plv.parent_project_name AS parent_project_name_full, - rp.related_project_ids, - rp.related_project_ids_searchable, + rp.related_project_ids_with_self AS related_project_ids, + rp.related_project_ids_searchable_with_self AS related_project_ids_searchable, plv.knack_project_id AS knack_data_tracker_project_record_id, plv.project_url, (plv.project_url || '?tab=map&project_component_id='::text) || mpc.project_component_id::text AS component_url, From 8413c3b013d347336cc7bf9455c646adb5052d69 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 17 Jun 2024 17:11:08 -0500 Subject: [PATCH 21/27] Remove phase_start not null condition for estimated substantial date field --- .../1718314926409_add_council_districts_searchable/up.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index e9105da65d..319d7e06a7 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -125,7 +125,6 @@ min_phase_dates AS ( WHERE mpp.is_phase_end_confirmed = false AND mpp.is_phase_start_confirmed = false - AND phase_start IS NOT null AND mpp.is_deleted = false AND mp.phase_name_simple = 'Complete'::text GROUP BY From 06bea1360d8d53f3774ca422e532a3381e9a9383 Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Mon, 17 Jun 2024 22:12:12 +0000 Subject: [PATCH 22/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-other-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moped-database/views/component_arcgis_online_view.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index 969bc1457a..a3900bed27 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -121,7 +121,7 @@ min_phase_dates AS ( min(mpp.phase_end) AS min_phase_end FROM moped_proj_phases mpp LEFT JOIN moped_phases mp ON mpp.phase_id = mp.phase_id - WHERE mpp.is_phase_end_confirmed = false AND mpp.is_phase_start_confirmed = false AND mpp.phase_start IS NOT null AND mpp.is_deleted = false AND mp.phase_name_simple = 'Complete'::text + WHERE mpp.is_phase_end_confirmed = false AND mpp.is_phase_start_confirmed = false AND mpp.is_deleted = false AND mp.phase_name_simple = 'Complete'::text GROUP BY mpp.project_id ) From 1df357d828b691a6b91cc5d1a496aa37fa74a176 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 19 Jun 2024 15:51:48 -0500 Subject: [PATCH 23/27] Filter out soft deleted child projects from related projects list --- .../1718314926409_add_council_districts_searchable/up.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index 319d7e06a7..0fc5c29c76 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -110,6 +110,7 @@ related_projects AS ( concat_ws(', ', lpad(pmp.project_id::text, 5, '0'), string_agg(lpad(cmp.project_id::text, 5, '0'), ', '::text)) AS related_project_ids_searchable_with_self FROM moped_project AS pmp LEFT JOIN moped_project AS cmp ON pmp.project_id = cmp.parent_project_id + WHERE cmp.is_deleted = false GROUP BY pmp.project_id ), From 8fac31d0b2c9f226d64baa6d681d938c0d56fd60 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 19 Jun 2024 20:52:48 -0500 Subject: [PATCH 24/27] Refactor substantial complete date and add estimated substantial complete date to plv and then agol view --- .../down.sql | 231 ++++++++++++++ .../up.sql | 302 +++++++++++++++++- 2 files changed, 532 insertions(+), 1 deletion(-) diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/down.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/down.sql index bb28bf63e1..69ae4185ca 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/down.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/down.sql @@ -1,4 +1,235 @@ DROP VIEW IF EXISTS component_arcgis_online_view; +DROP VIEW IF EXISTS project_list_view; + +CREATE OR REPLACE VIEW project_list_view AS WITH project_person_list_lookup AS ( + SELECT + mpp.project_id, + string_agg(DISTINCT concat(mu.first_name, ' ', mu.last_name, ':', mpr.project_role_name), ','::text) AS project_team_members + FROM moped_proj_personnel AS mpp + INNER JOIN moped_users AS mu ON mpp.user_id = mu.user_id + INNER JOIN moped_proj_personnel_roles AS mppr ON mpp.project_personnel_id = mppr.project_personnel_id + INNER JOIN moped_project_roles AS mpr ON mppr.project_role_id = mpr.project_role_id + WHERE mpp.is_deleted = false AND mppr.is_deleted = false + GROUP BY mpp.project_id +), + +funding_sources_lookup AS ( + SELECT + mpf_1.project_id, + string_agg(mfs.funding_source_name, ', '::text) AS funding_source_name + FROM moped_proj_funding AS mpf_1 + LEFT JOIN moped_fund_sources AS mfs ON mpf_1.funding_source_id = mfs.funding_source_id + WHERE mpf_1.is_deleted = false + GROUP BY mpf_1.project_id +), + +project_type_lookup AS ( + SELECT + mpt.project_id, + string_agg(mt.type_name, ', '::text) AS type_name + FROM moped_project_types AS mpt + LEFT JOIN moped_types AS mt ON mpt.project_type_id = mt.type_id AND mpt.is_deleted = false + GROUP BY mpt.project_id +), + +child_project_lookup AS ( + SELECT + jsonb_agg(children.project_id) AS children_project_ids, + children.parent_project_id AS parent_id + FROM moped_project AS children + INNER JOIN moped_project AS parent ON children.parent_project_id = parent.project_id + WHERE children.is_deleted = false + GROUP BY children.parent_project_id +), + +work_activities AS ( + SELECT + mpwa.project_id, + string_agg(task_order_objects.task_order_object ->> 'display_name'::text, ', '::text) AS task_order_names, + string_agg(task_order_objects.task_order_object ->> 'task_order'::text, ', '::text) AS task_order_names_short, + jsonb_agg(DISTINCT task_order_objects.task_order_object) FILTER (WHERE task_order_objects.task_order_object IS NOT null) AS task_orders, + string_agg(DISTINCT mpwa.workgroup_contractor, ', '::text) AS workgroup_contractors, + string_agg(mpwa.contract_number, ', '::text) AS contract_numbers + FROM moped_proj_work_activity AS mpwa + LEFT JOIN LATERAL jsonb_array_elements(mpwa.task_orders) AS task_order_objects (task_order_object) ON true + WHERE 1 = 1 AND mpwa.is_deleted = false + GROUP BY mpwa.project_id +), + +moped_proj_components_subtypes AS ( + SELECT + mpc.project_id, + string_agg(DISTINCT mc.component_name_full, ', '::text) AS components + FROM moped_proj_components AS mpc + LEFT JOIN moped_components AS mc ON mpc.component_id = mc.component_id + WHERE mpc.is_deleted = false + GROUP BY mpc.project_id +), + +project_district_association AS ( + WITH project_council_district_map AS ( + SELECT DISTINCT + moped_project.project_id, + features_council_districts.council_district_id + FROM moped_project + LEFT JOIN moped_proj_components ON moped_project.project_id = moped_proj_components.project_id + LEFT JOIN features ON moped_proj_components.project_component_id = features.component_id + LEFT JOIN features_council_districts ON features.id = features_council_districts.feature_id + WHERE features.is_deleted IS false AND moped_proj_components.is_deleted IS false + ), + + parent_child_project_map AS ( + SELECT + parent_projects.project_id, + unnest(ARRAY[parent_projects.project_id] || array_agg(child_projects.project_id)) AS self_and_children_project_ids + FROM moped_project AS parent_projects + LEFT JOIN moped_project AS child_projects ON parent_projects.project_id = child_projects.parent_project_id + GROUP BY parent_projects.project_id + ORDER BY parent_projects.project_id + ) + + SELECT + projects.project_id, + array_agg(DISTINCT project_districts.council_district_id) FILTER (WHERE project_districts.council_district_id IS NOT null) AS project_council_districts, + array_agg(DISTINCT project_and_children_districts.council_district_id) FILTER (WHERE project_and_children_districts.council_district_id IS NOT null) AS project_and_child_project_council_districts + FROM parent_child_project_map AS projects + LEFT JOIN project_council_district_map AS project_and_children_districts ON projects.self_and_children_project_ids = project_and_children_districts.project_id + LEFT JOIN project_council_district_map AS project_districts ON projects.project_id = project_districts.project_id + GROUP BY projects.project_id +) + +SELECT + mp.project_id, + mp.project_name_full, + mp.project_name, + mp.project_name_secondary, + mp.project_description, + mp.ecapris_subproject_id, + mp.project_website, + mp.date_added, + mp.is_deleted, + mp.updated_at, + current_phase.phase_name AS current_phase, + current_phase.phase_key AS current_phase_key, + current_phase.phase_name_simple AS current_phase_simple, + ppll.project_team_members, + me.entity_name AS project_sponsor, + mel.entity_name AS project_lead, + mpps.name AS public_process_status, + mp.interim_project_id, + mp.parent_project_id, + mp.knack_project_id, + 'https://mobility.austin.gov/moped/projects/'::text || mp.project_id::text AS project_url, + 'https://mobility.austin.gov/moped/projects/'::text || mp.parent_project_id::text AS parent_project_url, + proj_status_update.project_note AS project_status_update, + proj_status_update.date_created AS project_status_update_date_created, + work_activities.workgroup_contractors, + work_activities.contract_numbers, + work_activities.task_order_names, + work_activities.task_order_names_short, + work_activities.task_orders, + 'placeholder text'::text AS project_development_status, + '2024-01-01T00:00:00-06:00'::text AS project_development_status_date, + 9999 AS project_development_status_date_calendar_year, + 'placeholder text'::text AS project_development_status_date_calendar_year_month, + 'placeholder text'::text AS project_development_status_date_calendar_year_month_numeric, + 'placeholder text'::text AS project_development_status_date_calendar_year_quarter, + 999 AS project_development_status_date_fiscal_year, + 'placeholder text'::text AS project_development_status_date_fiscal_year_quarter, + ( + SELECT moped_project.project_name_full + FROM moped_project + WHERE moped_project.project_id = mp.parent_project_id + ) AS parent_project_name, + cpl.children_project_ids, + string_agg(DISTINCT me2.entity_name, ', '::text) AS project_partners, + ( + SELECT json_agg(json_build_object('signal_id', feature_signals.signal_id, 'knack_id', feature_signals.knack_id, 'location_name', feature_signals.location_name, 'signal_type', feature_signals.signal_type, 'id', feature_signals.id)) AS json_agg + FROM moped_proj_components AS components + LEFT JOIN feature_signals ON components.project_component_id = feature_signals.component_id + WHERE true AND components.is_deleted = false AND components.project_id = mp.project_id AND feature_signals.signal_id IS NOT null AND feature_signals.is_deleted = false + ) AS project_feature, + fsl.funding_source_name, + ptl.type_name, + ( + SELECT min(phases.phase_start) AS min + FROM moped_proj_phases AS phases + WHERE true AND phases.project_id = mp.project_id AND phases.phase_id = 9 AND phases.is_deleted = false + ) AS construction_start_date, + ( + SELECT max(phases.phase_end) AS max + FROM moped_proj_phases AS phases + WHERE true AND phases.project_id = mp.project_id AND phases.phase_id = 11 AND phases.is_deleted = false + ) AS completion_end_date, + ( + SELECT min(min_confirmed_dates.min_confirmed_date) AS min + FROM ( + SELECT min(phases.phase_start) AS min_confirmed_date + FROM moped_proj_phases AS phases + LEFT JOIN moped_phases ON phases.phase_id = moped_phases.phase_id + WHERE true AND phases.phase_start IS NOT null AND phases.is_phase_start_confirmed = true AND phases.project_id = mp.project_id AND moped_phases.phase_name_simple = 'Complete'::text AND phases.is_deleted = false + UNION ALL + SELECT min(phases.phase_end) AS min_confirmed_date + FROM moped_proj_phases AS phases + LEFT JOIN moped_phases ON phases.phase_id = moped_phases.phase_id + WHERE true AND phases.phase_end IS NOT null AND phases.is_phase_end_confirmed = true AND phases.project_id = mp.project_id AND moped_phases.phase_name_simple = 'Complete'::text AND phases.is_deleted = false + ) AS min_confirmed_dates + ) AS substantial_completion_date, + ( + SELECT string_agg(concat(users.first_name, ' ', users.last_name), ', '::text) AS string_agg + FROM moped_proj_personnel AS mpp + INNER JOIN moped_users AS users ON mpp.user_id = users.user_id + INNER JOIN moped_proj_personnel_roles AS mppr ON mpp.project_personnel_id = mppr.project_personnel_id + INNER JOIN moped_project_roles AS mpr ON mppr.project_role_id = mpr.project_role_id + WHERE 1 = 1 AND mpr.project_role_name = 'Inspector'::text AND mpp.is_deleted = false AND mppr.is_deleted = false AND mpp.project_id = mp.project_id + GROUP BY mpp.project_id + ) AS project_inspector, + ( + SELECT string_agg(concat(users.first_name, ' ', users.last_name), ', '::text) AS string_agg + FROM moped_proj_personnel AS mpp + INNER JOIN moped_users AS users ON mpp.user_id = users.user_id + INNER JOIN moped_proj_personnel_roles AS mppr ON mpp.project_personnel_id = mppr.project_personnel_id + INNER JOIN moped_project_roles AS mpr ON mppr.project_role_id = mpr.project_role_id + WHERE 1 = 1 AND mpr.project_role_name = 'Designer'::text AND mpp.is_deleted = false AND mppr.is_deleted = false AND mpp.project_id = mp.project_id + GROUP BY mpp.project_id + ) AS project_designer, + ( + SELECT string_agg(tags.name, ', '::text) AS string_agg + FROM moped_proj_tags AS ptags + INNER JOIN moped_tags AS tags ON ptags.tag_id = tags.id + WHERE 1 = 1 AND ptags.is_deleted = false AND ptags.project_id = mp.project_id + GROUP BY ptags.project_id + ) AS project_tags, + concat(added_by_user.first_name, ' ', added_by_user.last_name) AS added_by, + mpcs.components, + districts.project_council_districts, + districts.project_and_child_project_council_districts +FROM moped_project AS mp +LEFT JOIN project_person_list_lookup AS ppll ON mp.project_id = ppll.project_id +LEFT JOIN funding_sources_lookup AS fsl ON mp.project_id = fsl.project_id +LEFT JOIN project_type_lookup AS ptl ON mp.project_id = ptl.project_id +LEFT JOIN moped_entity AS me ON mp.project_sponsor = me.entity_id +LEFT JOIN moped_entity AS mel ON mp.project_lead_id = mel.entity_id +LEFT JOIN moped_proj_partners AS mpp2 ON mp.project_id = mpp2.project_id AND mpp2.is_deleted = false +LEFT JOIN moped_entity AS me2 ON mpp2.entity_id = me2.entity_id +LEFT JOIN work_activities ON mp.project_id = work_activities.project_id +LEFT JOIN moped_users AS added_by_user ON mp.added_by = added_by_user.user_id +LEFT JOIN current_phase_view AS current_phase ON mp.project_id = current_phase.project_id +LEFT JOIN moped_public_process_statuses AS mpps ON mp.public_process_status_id = mpps.id +LEFT JOIN child_project_lookup AS cpl ON mp.project_id = cpl.parent_id +LEFT JOIN moped_proj_components_subtypes AS mpcs ON mp.project_id = mpcs.project_id +LEFT JOIN project_district_association AS districts ON mp.project_id = districts.project_id +LEFT JOIN LATERAL ( + SELECT + mpn.project_note, + mpn.created_at AS date_created + FROM moped_proj_notes AS mpn + WHERE mpn.project_id = mp.project_id AND mpn.project_note_type = 2 AND mpn.is_deleted = false + ORDER BY mpn.created_at DESC + LIMIT 1 +) AS proj_status_update ON true +WHERE mp.is_deleted = false +GROUP BY mp.project_id, mp.project_name, mp.project_description, ppll.project_team_members, mp.ecapris_subproject_id, mp.date_added, mp.is_deleted, me.entity_name, mel.entity_name, mp.updated_at, mp.interim_project_id, mp.parent_project_id, mp.knack_project_id, current_phase.phase_name, current_phase.phase_key, current_phase.phase_name_simple, ptl.type_name, mpcs.components, fsl.funding_source_name, added_by_user.first_name, added_by_user.last_name, mpps.name, cpl.children_project_ids, proj_status_update.project_note, proj_status_update.date_created, work_activities.workgroup_contractors, work_activities.contract_numbers, work_activities.task_order_names, work_activities.task_order_names_short, work_activities.task_orders, districts.project_council_districts, districts.project_and_child_project_council_districts; CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( SELECT diff --git a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql index 0fc5c29c76..b0eff26f96 100644 --- a/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql +++ b/moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql @@ -1,4 +1,304 @@ DROP VIEW IF EXISTS component_arcgis_online_view; +DROP VIEW IF EXISTS project_list_view; + +-- Refactor substantial_comletion_date and add substantial_completion_date_estimated to project_list_view + +CREATE OR REPLACE VIEW project_list_view AS WITH project_person_list_lookup AS ( + SELECT + mpp.project_id, + string_agg(DISTINCT concat(mu.first_name, ' ', mu.last_name, ':', mpr.project_role_name), ','::text) AS project_team_members + FROM moped_proj_personnel AS mpp + INNER JOIN moped_users AS mu ON mpp.user_id = mu.user_id + INNER JOIN moped_proj_personnel_roles AS mppr ON mpp.project_personnel_id = mppr.project_personnel_id + INNER JOIN moped_project_roles AS mpr ON mppr.project_role_id = mpr.project_role_id + WHERE mpp.is_deleted = false AND mppr.is_deleted = false + GROUP BY mpp.project_id +), + +funding_sources_lookup AS ( + SELECT + mpf_1.project_id, + string_agg(mfs.funding_source_name, ', '::text) AS funding_source_name + FROM moped_proj_funding AS mpf_1 + LEFT JOIN moped_fund_sources AS mfs ON mpf_1.funding_source_id = mfs.funding_source_id + WHERE mpf_1.is_deleted = false + GROUP BY mpf_1.project_id +), + +project_type_lookup AS ( + SELECT + mpt.project_id, + string_agg(mt.type_name, ', '::text) AS type_name + FROM moped_project_types AS mpt + LEFT JOIN moped_types AS mt ON mpt.project_type_id = mt.type_id AND mpt.is_deleted = false + GROUP BY mpt.project_id +), + +child_project_lookup AS ( + SELECT + jsonb_agg(children.project_id) AS children_project_ids, + children.parent_project_id AS parent_id + FROM moped_project AS children + INNER JOIN moped_project AS parent ON children.parent_project_id = parent.project_id + WHERE children.is_deleted = false + GROUP BY children.parent_project_id +), + +work_activities AS ( + SELECT + mpwa.project_id, + string_agg(task_order_objects.task_order_object ->> 'display_name'::text, ', '::text) AS task_order_names, + string_agg(task_order_objects.task_order_object ->> 'task_order'::text, ', '::text) AS task_order_names_short, + jsonb_agg(DISTINCT task_order_objects.task_order_object) FILTER (WHERE task_order_objects.task_order_object IS NOT null) AS task_orders, + string_agg(DISTINCT mpwa.workgroup_contractor, ', '::text) AS workgroup_contractors, + string_agg(mpwa.contract_number, ', '::text) AS contract_numbers + FROM moped_proj_work_activity AS mpwa + LEFT JOIN LATERAL jsonb_array_elements(mpwa.task_orders) AS task_order_objects (task_order_object) ON true + WHERE 1 = 1 AND mpwa.is_deleted = false + GROUP BY mpwa.project_id +), + +moped_proj_components_subtypes AS ( + SELECT + mpc.project_id, + string_agg(DISTINCT mc.component_name_full, ', '::text) AS components + FROM moped_proj_components AS mpc + LEFT JOIN moped_components AS mc ON mpc.component_id = mc.component_id + WHERE mpc.is_deleted = false + GROUP BY mpc.project_id +), + +project_district_association AS ( + WITH project_council_district_map AS ( + SELECT DISTINCT + moped_project.project_id, + features_council_districts.council_district_id + FROM moped_project + LEFT JOIN moped_proj_components ON moped_project.project_id = moped_proj_components.project_id + LEFT JOIN features ON moped_proj_components.project_component_id = features.component_id + LEFT JOIN features_council_districts ON features.id = features_council_districts.feature_id + WHERE features.is_deleted IS false AND moped_proj_components.is_deleted IS false + ), + + parent_child_project_map AS ( + SELECT + parent_projects.project_id, + unnest(ARRAY[parent_projects.project_id] || array_agg(child_projects.project_id)) AS self_and_children_project_ids + FROM moped_project AS parent_projects + LEFT JOIN moped_project AS child_projects ON parent_projects.project_id = child_projects.parent_project_id + GROUP BY parent_projects.project_id + ORDER BY parent_projects.project_id + ) + + SELECT + projects.project_id, + array_agg(DISTINCT project_districts.council_district_id) FILTER (WHERE project_districts.council_district_id IS NOT null) AS project_council_districts, + array_agg(DISTINCT project_and_children_districts.council_district_id) FILTER (WHERE project_and_children_districts.council_district_id IS NOT null) AS project_and_child_project_council_districts + FROM parent_child_project_map AS projects + LEFT JOIN project_council_district_map AS project_and_children_districts ON projects.self_and_children_project_ids = project_and_children_districts.project_id + LEFT JOIN project_council_district_map AS project_districts ON projects.project_id = project_districts.project_id + GROUP BY projects.project_id +), + +min_confirmed_phase_dates AS ( + WITH min_dates AS ( + SELECT + phases.project_id, + min(phases.phase_start) AS min_date + FROM moped_proj_phases AS phases + LEFT JOIN moped_phases + ON phases.phase_id = moped_phases.phase_id WHERE true + AND phases.phase_start IS NOT null + AND phases.is_phase_start_confirmed = true + AND moped_phases.phase_name_simple = 'Complete'::text + AND phases.is_deleted = false + GROUP BY + phases.project_id + UNION ALL + SELECT + phases.project_id, + min(phases.phase_end) AS min_date + FROM moped_proj_phases AS phases + LEFT JOIN moped_phases + ON phases.phase_id = moped_phases.phase_id WHERE true + AND phases.phase_end IS NOT null + AND phases.is_phase_end_confirmed = true + AND moped_phases.phase_name_simple = 'Complete'::text + AND phases.is_deleted = false + GROUP BY + phases.project_id + ) + + SELECT + min_dates.project_id, + min(min_dates.min_date) AS min_phase_date + FROM min_dates + GROUP BY + min_dates.project_id +), + +min_estimated_phase_dates AS ( + WITH min_dates AS ( + SELECT + phases.project_id, + min(phases.phase_start) AS min_date + FROM moped_proj_phases AS phases + LEFT JOIN moped_phases + ON phases.phase_id = moped_phases.phase_id WHERE true + AND phases.phase_start IS NOT null + AND phases.is_phase_start_confirmed = false + AND moped_phases.phase_name_simple = 'Complete'::text + AND phases.is_deleted = false + GROUP BY + phases.project_id + UNION ALL + SELECT + phases.project_id, + min(phases.phase_end) AS min_date + FROM moped_proj_phases AS phases + LEFT JOIN moped_phases + ON phases.phase_id = moped_phases.phase_id WHERE true + AND phases.phase_end IS NOT null + AND phases.is_phase_end_confirmed = false + AND moped_phases.phase_name_simple = 'Complete'::text + AND phases.is_deleted = false + GROUP BY + phases.project_id + ) + + SELECT + min_dates.project_id, + min(min_dates.min_date) AS min_phase_date + FROM min_dates + GROUP BY + min_dates.project_id +) + + +SELECT + mp.project_id, + mp.project_name_full, + mp.project_name, + mp.project_name_secondary, + mp.project_description, + mp.ecapris_subproject_id, + mp.project_website, + mp.date_added, + mp.is_deleted, + mp.updated_at, + current_phase.phase_name AS current_phase, + current_phase.phase_key AS current_phase_key, + current_phase.phase_name_simple AS current_phase_simple, + ppll.project_team_members, + me.entity_name AS project_sponsor, + mel.entity_name AS project_lead, + mpps.name AS public_process_status, + mp.interim_project_id, + mp.parent_project_id, + mp.knack_project_id, + 'https://mobility.austin.gov/moped/projects/'::text || mp.project_id::text AS project_url, + 'https://mobility.austin.gov/moped/projects/'::text || mp.parent_project_id::text AS parent_project_url, + proj_status_update.project_note AS project_status_update, + proj_status_update.date_created AS project_status_update_date_created, + work_activities.workgroup_contractors, + work_activities.contract_numbers, + work_activities.task_order_names, + work_activities.task_order_names_short, + work_activities.task_orders, + 'placeholder text'::text AS project_development_status, + '2024-01-01T00:00:00-06:00'::text AS project_development_status_date, + 9999 AS project_development_status_date_calendar_year, + 'placeholder text'::text AS project_development_status_date_calendar_year_month, + 'placeholder text'::text AS project_development_status_date_calendar_year_month_numeric, + 'placeholder text'::text AS project_development_status_date_calendar_year_quarter, + 999 AS project_development_status_date_fiscal_year, + 'placeholder text'::text AS project_development_status_date_fiscal_year_quarter, + ( + SELECT moped_project.project_name_full + FROM moped_project + WHERE moped_project.project_id = mp.parent_project_id + ) AS parent_project_name, + cpl.children_project_ids, + string_agg(DISTINCT me2.entity_name, ', '::text) AS project_partners, + ( + SELECT json_agg(json_build_object('signal_id', feature_signals.signal_id, 'knack_id', feature_signals.knack_id, 'location_name', feature_signals.location_name, 'signal_type', feature_signals.signal_type, 'id', feature_signals.id)) AS json_agg + FROM moped_proj_components AS components + LEFT JOIN feature_signals ON components.project_component_id = feature_signals.component_id + WHERE true AND components.is_deleted = false AND components.project_id = mp.project_id AND feature_signals.signal_id IS NOT null AND feature_signals.is_deleted = false + ) AS project_feature, + fsl.funding_source_name, + ptl.type_name, + ( + SELECT min(phases.phase_start) AS min + FROM moped_proj_phases AS phases + WHERE true AND phases.project_id = mp.project_id AND phases.phase_id = 9 AND phases.is_deleted = false + ) AS construction_start_date, + ( + SELECT max(phases.phase_end) AS max + FROM moped_proj_phases AS phases + WHERE true AND phases.project_id = mp.project_id AND phases.phase_id = 11 AND phases.is_deleted = false + ) AS completion_end_date, + mcpd.min_phase_date AS substantial_completion_date, + CASE WHEN mcpd.min_phase_date IS NOT null THEN null ELSE mepd.min_phase_date END AS substantial_completion_date_estimated, + ( + SELECT string_agg(concat(users.first_name, ' ', users.last_name), ', '::text) AS string_agg + FROM moped_proj_personnel AS mpp + INNER JOIN moped_users AS users ON mpp.user_id = users.user_id + INNER JOIN moped_proj_personnel_roles AS mppr ON mpp.project_personnel_id = mppr.project_personnel_id + INNER JOIN moped_project_roles AS mpr ON mppr.project_role_id = mpr.project_role_id + WHERE 1 = 1 AND mpr.project_role_name = 'Inspector'::text AND mpp.is_deleted = false AND mppr.is_deleted = false AND mpp.project_id = mp.project_id + GROUP BY mpp.project_id + ) AS project_inspector, + ( + SELECT string_agg(concat(users.first_name, ' ', users.last_name), ', '::text) AS string_agg + FROM moped_proj_personnel AS mpp + INNER JOIN moped_users AS users ON mpp.user_id = users.user_id + INNER JOIN moped_proj_personnel_roles AS mppr ON mpp.project_personnel_id = mppr.project_personnel_id + INNER JOIN moped_project_roles AS mpr ON mppr.project_role_id = mpr.project_role_id + WHERE 1 = 1 AND mpr.project_role_name = 'Designer'::text AND mpp.is_deleted = false AND mppr.is_deleted = false AND mpp.project_id = mp.project_id + GROUP BY mpp.project_id + ) AS project_designer, + ( + SELECT string_agg(tags.name, ', '::text) AS string_agg + FROM moped_proj_tags AS ptags + INNER JOIN moped_tags AS tags ON ptags.tag_id = tags.id + WHERE 1 = 1 AND ptags.is_deleted = false AND ptags.project_id = mp.project_id + GROUP BY ptags.project_id + ) AS project_tags, + concat(added_by_user.first_name, ' ', added_by_user.last_name) AS added_by, + mpcs.components, + districts.project_council_districts, + districts.project_and_child_project_council_districts +FROM moped_project AS mp +LEFT JOIN project_person_list_lookup AS ppll ON mp.project_id = ppll.project_id +LEFT JOIN funding_sources_lookup AS fsl ON mp.project_id = fsl.project_id +LEFT JOIN project_type_lookup AS ptl ON mp.project_id = ptl.project_id +LEFT JOIN moped_entity AS me ON mp.project_sponsor = me.entity_id +LEFT JOIN moped_entity AS mel ON mp.project_lead_id = mel.entity_id +LEFT JOIN moped_proj_partners AS mpp2 ON mp.project_id = mpp2.project_id AND mpp2.is_deleted = false +LEFT JOIN moped_entity AS me2 ON mpp2.entity_id = me2.entity_id +LEFT JOIN work_activities ON mp.project_id = work_activities.project_id +LEFT JOIN moped_users AS added_by_user ON mp.added_by = added_by_user.user_id +LEFT JOIN current_phase_view AS current_phase ON mp.project_id = current_phase.project_id +LEFT JOIN moped_public_process_statuses AS mpps ON mp.public_process_status_id = mpps.id +LEFT JOIN child_project_lookup AS cpl ON mp.project_id = cpl.parent_id +LEFT JOIN moped_proj_components_subtypes AS mpcs ON mp.project_id = mpcs.project_id +LEFT JOIN project_district_association AS districts ON mp.project_id = districts.project_id +LEFT JOIN min_confirmed_phase_dates AS mcpd ON mp.project_id = mcpd.project_id +LEFT JOIN min_estimated_phase_dates AS mepd ON mp.project_id = mepd.project_id +LEFT JOIN LATERAL ( + SELECT + mpn.project_note, + mpn.created_at AS date_created + FROM moped_proj_notes AS mpn + WHERE mpn.project_id = mp.project_id AND mpn.project_note_type = 2 AND mpn.is_deleted = false + ORDER BY mpn.created_at DESC + LIMIT 1 +) AS proj_status_update ON true +WHERE mp.is_deleted = false +GROUP BY mp.project_id, mp.project_name, mp.project_description, ppll.project_team_members, mp.ecapris_subproject_id, mp.date_added, mp.is_deleted, me.entity_name, mel.entity_name, mp.updated_at, mp.interim_project_id, mp.parent_project_id, mp.knack_project_id, current_phase.phase_name, current_phase.phase_key, current_phase.phase_name_simple, ptl.type_name, mpcs.components, fsl.funding_source_name, added_by_user.first_name, added_by_user.last_name, mpps.name, cpl.children_project_ids, proj_status_update.project_note, proj_status_update.date_created, work_activities.workgroup_contractors, work_activities.contract_numbers, work_activities.task_order_names, work_activities.task_order_names_short, work_activities.task_orders, districts.project_council_districts, districts.project_and_child_project_council_districts, mepd.min_phase_date, mcpd.min_phase_date; + +-- Reference substantial_completion_date_estimated from project_list_view CREATE OR REPLACE VIEW component_arcgis_online_view AS WITH work_types AS ( SELECT @@ -167,7 +467,7 @@ SELECT mpc.interim_project_component_id, mpc.completion_date, coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, - CASE WHEN substantial_completion_date IS NOT null THEN null ELSE mpd.min_phase_date END AS substantial_completion_date_estimated, + plv.substantial_completion_date_estimated AS substantial_completion_date_estimated, mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, From fa4b4e8a795a26585cfbeb0942b9394e414f95ac Mon Sep 17 00:00:00 2001 From: Moped View Bot Date: Thu, 20 Jun 2024 01:53:51 +0000 Subject: [PATCH 25/27] =?UTF-8?q?=F0=9F=A4=96=20Export=20view=20for=20md-1?= =?UTF-8?q?7639-atsd-other-cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/component_arcgis_online_view.sql | 6 +- moped-database/views/project_list_view.sql | 77 +++++++++++++++---- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/moped-database/views/component_arcgis_online_view.sql b/moped-database/views/component_arcgis_online_view.sql index a3900bed27..449205566f 100644 --- a/moped-database/views/component_arcgis_online_view.sql +++ b/moped-database/views/component_arcgis_online_view.sql @@ -110,6 +110,7 @@ related_projects AS ( concat_ws(', '::text, lpad(pmp.project_id::text, 5, '0'::text), string_agg(lpad(cmp.project_id::text, 5, '0'::text), ', '::text)) AS related_project_ids_searchable_with_self FROM moped_project pmp LEFT JOIN moped_project cmp ON pmp.project_id = cmp.parent_project_id + WHERE cmp.is_deleted = false GROUP BY pmp.project_id ), @@ -155,10 +156,7 @@ SELECT mpc.interim_project_component_id, mpc.completion_date, coalesce(mpc.completion_date, plv.substantial_completion_date) AS substantial_completion_date, - CASE - WHEN plv.substantial_completion_date IS NOT null THEN null::timestamp with time zone - ELSE mpd.min_phase_date - END AS substantial_completion_date_estimated, + plv.substantial_completion_date_estimated, mpc.srts_id, mpc.location_description AS component_location_description, plv.project_name, diff --git a/moped-database/views/project_list_view.sql b/moped-database/views/project_list_view.sql index bf26158518..edeb9d7767 100644 --- a/moped-database/views/project_list_view.sql +++ b/moped-database/views/project_list_view.sql @@ -1,4 +1,4 @@ --- Most recent migration: moped-database/migrations/1713896796482_add_full_name_to_list_view/up.sql +-- Most recent migration: moped-database/migrations/1718314926409_add_council_districts_searchable/up.sql CREATE OR REPLACE VIEW project_list_view AS WITH project_person_list_lookup AS ( SELECT @@ -95,6 +95,58 @@ parent_child_project_map AS ( LEFT JOIN project_council_district_map project_and_children_districts ON projects.self_and_children_project_ids = project_and_children_districts.project_id LEFT JOIN project_council_district_map project_districts ON projects.project_id = project_districts.project_id GROUP BY projects.project_id +), + +min_confirmed_phase_dates AS ( + WITH min_dates AS ( + SELECT + phases.project_id, + min(phases.phase_start) AS min_date + FROM moped_proj_phases phases + LEFT JOIN moped_phases ON phases.phase_id = moped_phases.phase_id + WHERE true AND phases.phase_start IS NOT null AND phases.is_phase_start_confirmed = true AND moped_phases.phase_name_simple = 'Complete'::text AND phases.is_deleted = false + GROUP BY phases.project_id + UNION ALL + SELECT + phases.project_id, + min(phases.phase_end) AS min_date + FROM moped_proj_phases phases + LEFT JOIN moped_phases ON phases.phase_id = moped_phases.phase_id + WHERE true AND phases.phase_end IS NOT null AND phases.is_phase_end_confirmed = true AND moped_phases.phase_name_simple = 'Complete'::text AND phases.is_deleted = false + GROUP BY phases.project_id + ) + + SELECT + min_dates.project_id, + min(min_dates.min_date) AS min_phase_date + FROM min_dates + GROUP BY min_dates.project_id +), + +min_estimated_phase_dates AS ( + WITH min_dates AS ( + SELECT + phases.project_id, + min(phases.phase_start) AS min_date + FROM moped_proj_phases phases + LEFT JOIN moped_phases ON phases.phase_id = moped_phases.phase_id + WHERE true AND phases.phase_start IS NOT null AND phases.is_phase_start_confirmed = false AND moped_phases.phase_name_simple = 'Complete'::text AND phases.is_deleted = false + GROUP BY phases.project_id + UNION ALL + SELECT + phases.project_id, + min(phases.phase_end) AS min_date + FROM moped_proj_phases phases + LEFT JOIN moped_phases ON phases.phase_id = moped_phases.phase_id + WHERE true AND phases.phase_end IS NOT null AND phases.is_phase_end_confirmed = false AND moped_phases.phase_name_simple = 'Complete'::text AND phases.is_deleted = false + GROUP BY phases.project_id + ) + + SELECT + min_dates.project_id, + min(min_dates.min_date) AS min_phase_date + FROM min_dates + GROUP BY min_dates.project_id ) SELECT @@ -160,20 +212,11 @@ SELECT FROM moped_proj_phases phases WHERE true AND phases.project_id = mp.project_id AND phases.phase_id = 11 AND phases.is_deleted = false ) AS completion_end_date, - ( - SELECT min(min_confirmed_dates.min_confirmed_date) AS min - FROM ( - SELECT min(phases.phase_start) AS min_confirmed_date - FROM moped_proj_phases phases - LEFT JOIN moped_phases ON phases.phase_id = moped_phases.phase_id - WHERE true AND phases.phase_start IS NOT null AND phases.is_phase_start_confirmed = true AND phases.project_id = mp.project_id AND moped_phases.phase_name_simple = 'Complete'::text AND phases.is_deleted = false - UNION ALL - SELECT min(phases.phase_end) AS min_confirmed_date - FROM moped_proj_phases phases - LEFT JOIN moped_phases ON phases.phase_id = moped_phases.phase_id - WHERE true AND phases.phase_end IS NOT null AND phases.is_phase_end_confirmed = true AND phases.project_id = mp.project_id AND moped_phases.phase_name_simple = 'Complete'::text AND phases.is_deleted = false - ) min_confirmed_dates - ) AS substantial_completion_date, + mcpd.min_phase_date AS substantial_completion_date, + CASE + WHEN mcpd.min_phase_date IS NOT null THEN null::timestamp with time zone + ELSE mepd.min_phase_date + END AS substantial_completion_date_estimated, ( SELECT string_agg(concat(users.first_name, ' ', users.last_name), ', '::text) AS string_agg FROM moped_proj_personnel mpp @@ -218,6 +261,8 @@ LEFT JOIN moped_public_process_statuses mpps ON mp.public_process_status_id = mp LEFT JOIN child_project_lookup cpl ON mp.project_id = cpl.parent_id LEFT JOIN moped_proj_components_subtypes mpcs ON mp.project_id = mpcs.project_id LEFT JOIN project_district_association districts ON mp.project_id = districts.project_id +LEFT JOIN min_confirmed_phase_dates mcpd ON mp.project_id = mcpd.project_id +LEFT JOIN min_estimated_phase_dates mepd ON mp.project_id = mepd.project_id LEFT JOIN LATERAL ( SELECT mpn.project_note, @@ -228,4 +273,4 @@ LEFT JOIN LATERAL ( LIMIT 1 ) proj_status_update ON true WHERE mp.is_deleted = false -GROUP BY mp.project_id, mp.project_name, mp.project_description, ppll.project_team_members, mp.ecapris_subproject_id, mp.date_added, mp.is_deleted, me.entity_name, mel.entity_name, mp.updated_at, mp.interim_project_id, mp.parent_project_id, mp.knack_project_id, current_phase.phase_name, current_phase.phase_key, current_phase.phase_name_simple, ptl.type_name, mpcs.components, fsl.funding_source_name, added_by_user.first_name, added_by_user.last_name, mpps.name, cpl.children_project_ids, proj_status_update.project_note, proj_status_update.date_created, work_activities.workgroup_contractors, work_activities.contract_numbers, work_activities.task_order_names, work_activities.task_order_names_short, work_activities.task_orders, districts.project_council_districts, districts.project_and_child_project_council_districts; +GROUP BY mp.project_id, mp.project_name, mp.project_description, ppll.project_team_members, mp.ecapris_subproject_id, mp.date_added, mp.is_deleted, me.entity_name, mel.entity_name, mp.updated_at, mp.interim_project_id, mp.parent_project_id, mp.knack_project_id, current_phase.phase_name, current_phase.phase_key, current_phase.phase_name_simple, ptl.type_name, mpcs.components, fsl.funding_source_name, added_by_user.first_name, added_by_user.last_name, mpps.name, cpl.children_project_ids, proj_status_update.project_note, proj_status_update.date_created, work_activities.workgroup_contractors, work_activities.contract_numbers, work_activities.task_order_names, work_activities.task_order_names_short, work_activities.task_orders, districts.project_council_districts, districts.project_and_child_project_council_districts, mepd.min_phase_date, mcpd.min_phase_date; From de2c2aa27923416f3294ac401ecb2cd65d7f7e5b Mon Sep 17 00:00:00 2001 From: Frank Hereford Date: Thu, 20 Jun 2024 13:57:38 -0500 Subject: [PATCH 26/27] bump local dev graphql-engine version --- moped-database/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moped-database/docker-compose.yml b/moped-database/docker-compose.yml index 532b86a91a..15c8196371 100644 --- a/moped-database/docker-compose.yml +++ b/moped-database/docker-compose.yml @@ -1,7 +1,7 @@ # Architecture Independent Docker Stack Components for Moped Development Environment services: hasura: - image: hasura/graphql-engine:v2.39.2 + image: hasura/graphql-engine:v2.40.0 restart: always depends_on: - moped-pgsql From 46a3d2f7885206eaaa9d409ea62cd11c96de67dc Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 24 Jun 2024 15:48:56 -0500 Subject: [PATCH 27/27] Patch version --- moped-editor/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moped-editor/package.json b/moped-editor/package.json index b171af3e8f..a07f0e1328 100644 --- a/moped-editor/package.json +++ b/moped-editor/package.json @@ -2,7 +2,7 @@ "name": "atd-moped-editor", "author": "ATD Data & Technology Services", "license": "CC0-1.0", - "version": "2.13.0", + "version": "2.13.1", "homepage": "/moped", "private": false, "repository": {