Skip to content

Commit 509fe0c

Browse files
authored
Merge pull request #1193 from cityofaustin/v1.35.2
v1.35.2
2 parents 5d465a1 + 45d2c13 commit 509fe0c

File tree

17 files changed

+525
-7
lines changed

17 files changed

+525
-7
lines changed

moped-database/metadata/tables.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@
12201220
- line_representation
12211221
- feature_layer_id
12221222
- asset_feature_layer_id
1223+
- component_name_full
12231224
filter: {}
12241225
- role: moped-editor
12251226
permission:
@@ -1231,6 +1232,7 @@
12311232
- line_representation
12321233
- feature_layer_id
12331234
- asset_feature_layer_id
1235+
- component_name_full
12341236
filter: {}
12351237
- role: moped-viewer
12361238
permission:
@@ -1242,6 +1244,7 @@
12421244
- line_representation
12431245
- feature_layer_id
12441246
- asset_feature_layer_id
1247+
- component_name_full
12451248
filter: {}
12461249
- table:
12471250
name: moped_components_subcomponents
@@ -4908,6 +4911,7 @@
49084911
- updated_at
49094912
- knack_project_id
49104913
- project_note_date_created
4914+
- components
49114915
filter: {}
49124916
allow_aggregations: true
49134917
- role: moped-editor
@@ -4949,6 +4953,7 @@
49494953
- updated_at
49504954
- knack_project_id
49514955
- project_note_date_created
4956+
- components
49524957
filter: {}
49534958
allow_aggregations: true
49544959
- role: moped-viewer
@@ -4990,6 +4995,7 @@
49904995
- updated_at
49914996
- knack_project_id
49924997
- project_note_date_created
4998+
- components
49934999
filter: {}
49945000
allow_aggregations: true
49955001
- table:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE moped_components DROP COLUMN component_name_full;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ALTER TABLE moped_components
2+
ADD COLUMN component_name_full text
3+
GENERATED ALWAYS AS
4+
(CASE WHEN component_subtype IS NULL THEN component_name
5+
ELSE (component_name::text || ' - ' || component_subtype::text)
6+
END)
7+
STORED;
8+
9+
COMMENT ON COLUMN moped_components.component_name_full IS 'component name concatenated with component subtype, separated by -'
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
DROP VIEW project_list_view;
2+
3+
CREATE OR REPLACE VIEW public.project_list_view
4+
AS WITH project_person_list_lookup AS (
5+
SELECT
6+
mpp.project_id,
7+
string_agg(DISTINCT concat(mu.first_name, ' ', mu.last_name, ':', mpr.project_role_name), ','::text) AS project_team_members
8+
FROM moped_proj_personnel mpp
9+
JOIN moped_users mu ON mpp.user_id = mu.user_id
10+
JOIN moped_proj_personnel_roles mppr ON mpp.project_personnel_id = mppr.project_personnel_id
11+
JOIN moped_project_roles mpr ON mppr.project_role_id = mpr.project_role_id
12+
WHERE mpp.is_deleted = false
13+
AND mppr.is_deleted = false
14+
GROUP BY mpp.project_id
15+
), funding_sources_lookup AS (
16+
SELECT
17+
mpf_1.project_id,
18+
string_agg(mfs.funding_source_name, ', '::text) AS funding_source_name
19+
FROM moped_proj_funding mpf_1
20+
LEFT JOIN moped_fund_sources mfs ON mpf_1.funding_source_id = mfs.funding_source_id
21+
WHERE mpf_1.is_deleted = false
22+
GROUP BY mpf_1.project_id
23+
), project_type_lookup AS (
24+
SELECT
25+
mpt.project_id,
26+
string_agg(mt.type_name, ', '::text) AS type_name
27+
FROM moped_project_types mpt
28+
LEFT JOIN moped_types mt ON mpt.project_type_id = mt.type_id AND mpt.is_deleted = false
29+
GROUP BY mpt.project_id
30+
), child_project_lookup AS (
31+
SELECT jsonb_agg(children.project_id) AS children_project_ids,
32+
children.parent_project_id AS parent_id
33+
FROM moped_project AS children
34+
JOIN moped_project AS parent ON (parent.project_id = children.parent_project_id)
35+
WHERE children.is_deleted = false
36+
GROUP BY parent_id
37+
), work_activities AS (
38+
SELECT
39+
project_id,
40+
string_agg(task_order_objects.task_order_object ->> 'display_name'::text,
41+
', '::text) AS task_order_names,
42+
string_agg(task_order_objects.task_order_object ->> 'task_order'::text,
43+
', '::text) AS task_order_names_short,
44+
jsonb_agg(task_order_objects.task_order_object) FILTER (WHERE task_order_objects.task_order_object IS NOT NULL) AS task_orders,
45+
string_agg(DISTINCT mpwa.contractor,
46+
', '::text) AS contractors,
47+
string_agg(mpwa.contract_number,
48+
', '::text) AS contract_numbers FROM moped_proj_work_activity mpwa
49+
LEFT JOIN LATERAL jsonb_array_elements(mpwa.task_orders) task_order_objects (task_order_object) ON TRUE WHERE 1 = 1
50+
AND mpwa.is_deleted = FALSE
51+
GROUP BY
52+
mpwa.project_id
53+
)
54+
SELECT
55+
mp.project_id,
56+
mp.project_name,
57+
mp.project_description,
58+
mp.ecapris_subproject_id,
59+
mp.date_added,
60+
mp.is_deleted,
61+
mp.updated_at,
62+
current_phase.phase_name as current_phase,
63+
current_phase.phase_key as current_phase_key,
64+
current_phase.phase_name_simple as current_phase_simple,
65+
ppll.project_team_members,
66+
me.entity_name AS project_sponsor,
67+
mel.entity_name AS project_lead,
68+
mpps.name AS public_process_status,
69+
mp.interim_project_id,
70+
mp.parent_project_id,
71+
mp.knack_project_id,
72+
proj_notes.project_note,
73+
proj_notes.date_created as project_note_date_created,
74+
work_activities.contractors,
75+
work_activities.contract_numbers,
76+
work_activities.task_order_names,
77+
work_activities.task_order_names_short,
78+
work_activities.task_orders,
79+
(SELECT project_name
80+
FROM moped_project
81+
WHERE project_id = mp.parent_project_id
82+
) as parent_project_name,
83+
cpl.children_project_ids,
84+
string_agg(DISTINCT me2.entity_name, ', '::text) AS project_partner,
85+
(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))
86+
FROM moped_proj_components components
87+
LEFT JOIN feature_signals
88+
ON (feature_signals.component_id = components.project_component_id)
89+
WHERE TRUE
90+
AND components.is_deleted = false
91+
AND components.project_id = mp.project_id
92+
AND feature_signals.signal_id is not null
93+
AND feature_signals.is_deleted = false
94+
) as project_feature,
95+
fsl.funding_source_name,
96+
ptl.type_name,
97+
( -- get the date of the construction phase with the earliest start date
98+
SELECT min(phases.phase_start)
99+
FROM moped_proj_phases phases
100+
WHERE true
101+
AND phases.project_id = mp.project_id
102+
AND phases.phase_id = 9 -- phase_id 9 is construction
103+
AND phases.is_deleted = false
104+
) AS construction_start_date,
105+
( -- get the date of the completion phase with the latest end date
106+
SELECT max(phases.phase_end)
107+
FROM moped_proj_phases phases
108+
WHERE true
109+
AND phases.project_id = mp.project_id
110+
AND phases.phase_id = 11 -- phase_id 11 is complete
111+
AND phases.is_deleted = false
112+
) AS completion_end_date,
113+
( -- get me a list of the inspectors for this project
114+
SELECT string_agg(concat(users.first_name, ' ', users.last_name), ', '::text) AS string_agg
115+
FROM moped_proj_personnel mpp
116+
JOIN moped_users users ON mpp.user_id = users.user_id
117+
JOIN moped_proj_personnel_roles mppr ON mpp.project_personnel_id = mppr.project_personnel_id
118+
JOIN moped_project_roles mpr ON mppr.project_role_id = mpr.project_role_id
119+
WHERE 1 = 1
120+
AND mpr.project_role_name = 'Inspector'::text
121+
AND mpp.is_deleted = false
122+
AND mppr.is_deleted = false
123+
AND mpp.project_id = mp.project_id
124+
GROUP BY mpp.project_id) AS project_inspector,
125+
( -- get me a list of the designers for this project
126+
SELECT string_agg(concat(users.first_name, ' ', users.last_name), ', '::text) AS string_agg
127+
FROM moped_proj_personnel mpp
128+
JOIN moped_users users ON mpp.user_id = users.user_id
129+
JOIN moped_proj_personnel_roles mppr ON mpp.project_personnel_id = mppr.project_personnel_id
130+
JOIN moped_project_roles mpr ON mppr.project_role_id = mpr.project_role_id
131+
WHERE 1 = 1
132+
AND mpr.project_role_name = 'Designer'::text
133+
AND mpp.is_deleted = false
134+
AND mppr.is_deleted = false
135+
AND mpp.project_id = mp.project_id
136+
GROUP BY mpp.project_id) AS project_designer,
137+
( -- get me all of the tags added to a project
138+
SELECT string_agg(tags.name, ', '::text) AS string_agg
139+
FROM moped_proj_tags ptags
140+
JOIN moped_tags tags ON ptags.tag_id = tags.id
141+
WHERE 1 = 1
142+
AND ptags.is_deleted = false
143+
AND ptags.project_id = mp.project_id
144+
GROUP BY ptags.project_id) AS project_tags,
145+
concat(added_by_user.first_name, ' ', added_by_user.last_name) AS added_by
146+
FROM moped_project mp
147+
LEFT JOIN project_person_list_lookup ppll ON mp.project_id = ppll.project_id
148+
LEFT JOIN funding_sources_lookup fsl ON fsl.project_id = mp.project_id
149+
LEFT JOIN project_type_lookup ptl ON ptl.project_id = mp.project_id
150+
LEFT JOIN moped_entity me ON me.entity_id = mp.project_sponsor
151+
LEFT JOIN moped_entity mel ON mel.entity_id = mp.project_lead_id
152+
LEFT JOIN moped_proj_partners mpp2 ON mp.project_id = mpp2.project_id AND mpp2.is_deleted = false
153+
LEFT JOIN moped_entity me2 ON mpp2.entity_id = me2.entity_id
154+
LEFT JOIN work_activities on work_activities.project_id = mp.project_id
155+
LEFT JOIN moped_users added_by_user ON mp.added_by = added_by_user.user_id
156+
LEFT JOIN current_phase_view current_phase on mp.project_id = current_phase.project_id
157+
LEFT JOIN moped_public_process_statuses mpps ON mpps.id = mp.public_process_status_id
158+
LEFT JOIN child_project_lookup cpl on cpl.parent_id = mp.project_id
159+
LEFT JOIN LATERAL
160+
(
161+
SELECT mpn.project_note, mpn.date_created
162+
FROM moped_proj_notes mpn
163+
WHERE mpn.project_id = mp.project_id AND mpn.project_note_type = 2 AND mpn.is_deleted = false
164+
ORDER BY mpn.date_created DESC
165+
LIMIT 1
166+
) as proj_notes on true
167+
WHERE
168+
mp.is_deleted = false
169+
GROUP BY
170+
mp.project_id,
171+
mp.project_name,
172+
mp.project_description,
173+
ppll.project_team_members,
174+
mp.ecapris_subproject_id,
175+
mp.date_added,
176+
mp.is_deleted,
177+
me.entity_name,
178+
mel.entity_name,
179+
mp.updated_at,
180+
mp.interim_project_id,
181+
mp.parent_project_id,
182+
mp.knack_project_id,
183+
current_phase.phase_name,
184+
current_phase.phase_key,
185+
current_phase.phase_name_simple,
186+
ptl.type_name,
187+
fsl.funding_source_name,
188+
added_by_user.first_name,
189+
added_by_user.last_name,
190+
mpps.name,
191+
cpl.children_project_ids,
192+
proj_notes.project_note,
193+
proj_notes.date_created,
194+
work_activities.contractors,
195+
work_activities.contract_numbers,
196+
work_activities.task_order_names,
197+
work_activities.task_order_names_short,
198+
work_activities.task_orders;

0 commit comments

Comments
 (0)