-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2047 from bcgov/2024-rfi-attachments-computed-column
feat: rfi attachments computed column
- Loading branch information
Showing
7 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,11 @@ | |
sortable: true, | ||
}, | ||
}, | ||
'ccbc_public.extract_uuids': { | ||
tags: { | ||
omit: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- Deploy ccbc:computed_columns/rfi_attachments to pg | ||
|
||
begin; | ||
|
||
create or replace function ccbc_public.rfi_data_attachments(rfi ccbc_public.rfi_data) returns setof ccbc_public.attachment as | ||
$$ | ||
|
||
select * from ccbc_public.attachment where file in (select unnest(ccbc_public.extract_uuids(rfi.json_data))) order by created_at; | ||
|
||
$$ language sql stable; | ||
|
||
grant execute on function ccbc_public.rfi_data_attachments to ccbc_admin; | ||
grant execute on function ccbc_public.rfi_data_attachments to ccbc_analyst; | ||
|
||
comment on function ccbc_public.rfi_data_attachments is 'Computed column to return all attachement rows for an rfi_data row'; | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- Deploy ccbc:functions/extract_uuids to pg | ||
|
||
begin; | ||
|
||
create or replace function ccbc_public.extract_uuids(json_data jsonb) | ||
returns uuid[] as $$ | ||
declare | ||
result uuid[] := '{}'; | ||
queue jsonb[] := array[json_data]; | ||
current_element jsonb; | ||
iterator record; | ||
begin | ||
while array_length(queue,1) > 0 | ||
loop | ||
-- get first element from queue | ||
current_element := queue[1]; | ||
-- pop queued element | ||
queue := array_remove(queue, current_element); | ||
-- if we have an object | ||
if jsonb_typeof(current_element) = 'object' then | ||
for iterator in select * from jsonb_each(current_element) | ||
loop | ||
-- iterate through keys for uuid | ||
if iterator.key = 'uuid' then | ||
-- if uuid present, add to results | ||
result := array_append(result,(select trim( both '"' from iterator.value::text))::uuid); | ||
else | ||
-- otherwise, queue up others | ||
queue := array_append(queue,iterator.value); | ||
end if; | ||
end loop; | ||
end if; | ||
-- if we have a jsonb array | ||
if jsonb_typeof(current_element) = 'array' then | ||
-- iterate through jsonb array | ||
for iterator in select * from jsonb_array_elements(current_element) loop | ||
-- append to queue if jsonb is of type object (we aren't concerned with strings) | ||
if jsonb_typeof(iterator.value) = 'object' then | ||
queue := array_append(queue, iterator.value); | ||
end if; | ||
end loop; | ||
end if; | ||
end loop; | ||
return result; | ||
end; | ||
$$ language plpgsql; | ||
|
||
grant execute on function ccbc_public.extract_uuids to ccbc_auth_user, ccbc_analyst, ccbc_admin; | ||
|
||
comment on function ccbc_public.extract_uuids(jsonb) is 'Utility function to extract all uuids from a jsonb column'; | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Revert ccbc:computed_columns/rfi_attachments from pg | ||
|
||
begin; | ||
|
||
drop function ccbc_public.rfi_data_attachments(ccbc_public.rfi_data); | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- revert ccbc:functions/extract_uuids from pg | ||
|
||
begin; | ||
|
||
drop function ccbc_public.extract_uuids(jsonb); | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,6 +376,7 @@ mutations/archive_application 2023-07-26T22:48:25Z Rafael Solorzano <61289255+ra | |
mutations/archive_intake 2023-07-27T15:39:07Z Marcel Mueller <marcel@m2> # add mutation to soft delete/archive intake | ||
tables/intake_006_partial_unique 2023-07-27T20:03:03Z Marcel Mueller <marcel@m2> # drop unique constraint and add partial unique index | ||
@1.91.0 2023-08-02T21:36:10Z CCBC Service Account <[email protected]> # release v1.91.0 | ||
|
||
tables/application_community_progress_report_data 2023-08-03T18:33:03Z Rafael Solorzano <[email protected]> # create community progress report table | ||
@1.92.0 2023-08-04T20:51:41Z CCBC Service Account <[email protected]> # release v1.92.0 | ||
functions/extract_uuids 2023-08-03T19:24:48Z Anthony Bushara <[email protected]> # Utility function to extract uuids out of any jsonb provided | ||
computed_columns/rfi_data_attachments 2023-08-04T16:23:42Z Anthony Bushara <[email protected]> # Computed column to provide all attachments rows of an rfi |