-
Notifications
You must be signed in to change notification settings - Fork 4
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 #1570 from cityofaustin/v2.2.0
v2.2.0
- Loading branch information
Showing
42 changed files
with
572 additions
and
3,319 deletions.
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
FROM frankinaustin/postgis-multiarch:14-3.3 | ||
RUN apt-get update | ||
RUN apt-get install -y aptitude magic-wormhole vim | ||
RUN apt-get install -y aptitude vim |
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
3 changes: 3 additions & 0 deletions
3
database/metadata/databases/default/tables/public_view_crash_narratives_ocr_todo.yaml
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,3 @@ | ||
table: | ||
name: view_crash_narratives_ocr_todo | ||
schema: public |
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
7 changes: 7 additions & 0 deletions
7
database/migrations/default/1727375054583_narrative_ocr/down.sql
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 @@ | ||
drop view if exists view_crash_narratives_ocr_todo; | ||
|
||
alter table crashes_edits | ||
drop column investigator_narrative_ocr_processed_at; | ||
|
||
alter table crashes | ||
drop column investigator_narrative_ocr_processed_at; |
39 changes: 39 additions & 0 deletions
39
database/migrations/default/1727375054583_narrative_ocr/up.sql
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,39 @@ | ||
alter table crashes_edits | ||
add column investigator_narrative_ocr_processed_at timestamp with time zone; | ||
|
||
alter table crashes | ||
add column investigator_narrative_ocr_processed_at timestamp with time zone; | ||
|
||
comment on column crashes_edits.investigator_narrative_ocr_processed_at is 'The most recent | ||
timestamp at which the OCR process attempted to extract the investigator narrative. If null, | ||
indicates that the OCR narrative extract has never been attempted. This value should be set | ||
via ETL process.'; | ||
|
||
comment on column crashes.investigator_narrative_ocr_processed_at is 'The most recent | ||
timestamp at which the OCR process attempted to extract the investigator narrative. If null, | ||
indicates that the OCR narrative extract has never been attempted. This value should be set | ||
via ETL process on the crashes_edits table.'; | ||
|
||
create or replace view view_crash_narratives_ocr_todo as ( | ||
select | ||
id, | ||
cris_crash_id | ||
from | ||
crashes | ||
where | ||
cr3_stored_fl = TRUE | ||
and investigator_narrative is NULL | ||
and ( | ||
investigator_narrative_ocr_processed_at is NULL | ||
or cr3_processed_at >= investigator_narrative_ocr_processed_at | ||
) | ||
-- this issue started in Sep 2024 | ||
-- we do not OCR very old crashes | ||
and updated_at > '2024-09-01' | ||
order by | ||
cr3_processed_at asc, | ||
id asc | ||
); | ||
|
||
comment on view view_crash_narratives_ocr_todo is 'View which lists crashes which need to | ||
be processed by the OCR narrative extraction ETL' |
5 changes: 5 additions & 0 deletions
5
database/migrations/default/1727451510064_preserve_crash_narrative/down.sql
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,5 @@ | ||
drop trigger if exists | ||
crashes_cris_preserve_investigator_narrative_on_update on crashes_cris; | ||
|
||
drop function if exists | ||
public.crashes_cris_set_old_investigator_narrative; |
50 changes: 50 additions & 0 deletions
50
database/migrations/default/1727451510064_preserve_crash_narrative/up.sql
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,50 @@ | ||
create or replace function public.crashes_cris_set_old_investigator_narrative() | ||
returns trigger | ||
language plpgsql | ||
as $function$ | ||
begin | ||
new.investigator_narrative = old.investigator_narrative; | ||
return new; | ||
end; | ||
$function$; | ||
|
||
create or replace trigger crashes_cris_preserve_investigator_narrative_on_update | ||
before update on public.crashes_cris | ||
for each row | ||
when ( | ||
new.investigator_narrative is null and old.investigator_narrative is not null | ||
) | ||
execute procedure public.crashes_cris_set_old_investigator_narrative(); | ||
|
||
comment on function public.crashes_cris_set_old_investigator_narrative is 'Sets the | ||
investigator_narrative to its previous value if the updated value is null. This | ||
trigger function addresses a known CRIS bug in which updated crash records are | ||
missing the invesitgator narrative. It is tracked via DTS issue | ||
https://github.com/cityofaustin/atd-data-tech/issues/18971 and CRIS ticket #854366'; | ||
|
||
-- | ||
-- backfill narratives which have been erased | ||
-- run this manually to prevent migration timeout | ||
-- | ||
|
||
-- update | ||
-- crashes_cris | ||
-- set | ||
-- investigator_narrative = updates_todo.investigator_narrative_old | ||
-- from (select | ||
-- record_id as crash_pk, | ||
-- crashes.investigator_narrative as investigator_narrative_new, | ||
-- record_json -> 'old' ->> 'investigator_narrative' as investigator_narrative_old | ||
-- from | ||
-- change_log_crashes_cris as changes | ||
-- left join crashes on changes.record_id = crashes.id | ||
-- where | ||
-- record_json -> 'old' ->> 'investigator_narrative' is not null | ||
-- and record_json -> 'new' ->> 'investigator_narrative' is null | ||
-- and operation_type = 'UPDATE' | ||
-- and changes.created_at > '2024-09-09' | ||
-- and changes.created_by = 'cris' | ||
-- order by | ||
-- changes.id asc) as updates_todo | ||
-- where | ||
-- crashes_cris.id = updates_todo.crash_pk; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.