-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove crashes edits layer #1572
Conversation
@@ -17,15 +17,6 @@ object_relationships: | |||
- name: crashes_cri | |||
using: | |||
foreign_key_constraint_on: id | |||
- name: crashes_list_view |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the next PR where changes to the VZE are addressed i will need to recreate this view without references to the edits table, same for the locations view
@@ -325,3 +316,138 @@ select_permissions: | |||
- position | |||
filter: {} | |||
comment: "" | |||
update_permissions: | |||
- role: editor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crashes
table now has update permissions
new.wthr_cond_id | ||
); | ||
-- insert new (editable) vz record (only record ID) | ||
INSERT INTO public.crashes_edits (id) values (new.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the part of the function i deleted in the up migration
-- if the new cris value doesn't match the old cris value | ||
if(new_cris_jb -> column_name <> old_cris_jb -> column_name) then | ||
-- see if the unified record has the same value as the old cris value | ||
if (unified_record_jb -> column_name = old_cris_jb -> column_name) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is updated. now we are checking in the unified record value is equal to the old cris value, if so then there hasnt been a user edit so we want update the unified record with the new cris value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! this makes sense to me, and it is pretty nice to take advantage of the availability of the new and old values of the CRIS record and compare to the current crashes
record to determine what is or is not an edit. 😎
It's been a while since I've looked at this code so it was helpful for me to see the change isolated to the crashes table too. 💯
-- if the new value doesn't match the old | ||
if(new_cris_jb -> column_name <> old_cris_jb -> column_name) then | ||
-- see if the vz record has a value for this field | ||
if (edit_record_jb ->> column_name is null) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the part we changed in the up migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wowww—it works so well! code looks great; test steps look great. my only real feedback is related to the down migrations, which are missing some changes that were applied since we launched v2.0.
one other note wrt to testing, i added to your last test like so:
-- original test
select rpt_street_name from crashes where id = 10;
select rpt_street_name from crashes_cris where id = 10;
update crashes set rpt_street_name = null where id = 10;
select rpt_street_name from crashes where id = 10;
select rpt_street_name from crashes_cris where id = 10;
-- extra test - reset the unified value to match the _cris schema
update crashes set rpt_street_name = 'BELL' where id = 10;
-- edit the cris value
update crashes_cris set rpt_street_name = 'CRIS EDIT' where id = 10;
-- observe that the unified value is now back in sync with the cris value
select rpt_street_name from crashes where id = 10;
amazing stuff, Rose—thank you!
i'll hold off on approving this since it's now the collector branch for this feature 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like down is missing investigator_narrative_ocr_processed_at
column, and also change log insert trigger is missing. it might be good to use pg_dump
with the --schema-only
flag to make sure we captured everything that needs to be restored. but i might be overthinking it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yeah—also the on delete
constraints on these foreign key references have changed to restrict
. so i think the best move is to run a fresh schema dump and copy it into this migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for catching this -- just updated with new and improved down migra 🚀
|
||
drop trigger if exists insert_new_crashes_cris on public.crashes_cris; | ||
|
||
drop function if exists public.crashes_cris_insert_rows; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nbd, but i don't think you need drop the trigger of function since you're using if exists
later on (ditto for the up
migration)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was able to delete this drop trigger
part by adding cascade
to the end of the drop function
commands :)
|
||
SET default_tablespace = ''; | ||
|
||
SET default_table_access_method = heap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! you can remove this cruft ☝️and also the statements down below that set ownership to visionzero
. i think that's more of a best practice than anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I walked through your test steps, and I saw the expected results from the queries. I was able to trace the changes through the change log entries really easily as well. And, the import ran without error.
Really cool to see the power and flexibility of the json iterating triggers! 🚀 The future of nullability is looking bright!
-- if the new cris value doesn't match the old cris value | ||
if(new_cris_jb -> column_name <> old_cris_jb -> column_name) then | ||
-- see if the unified record has the same value as the old cris value | ||
if (unified_record_jb -> column_name = old_cris_jb -> column_name) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! this makes sense to me, and it is pretty nice to take advantage of the availability of the new and old values of the CRIS record and compare to the current crashes
record to determine what is or is not an edit. 😎
It's been a while since I've looked at this code so it was helpful for me to see the change isolated to the crashes table too. 💯
Update DB docs to remove _edits layer
Update OCR narrative ETL to work without _edits layer
…ision-zero into 19366_two_layer_model_vze
Make VZE compatible with the two-layer model
…edits Remove units and people edits layers
@johnclary @roseeichelmann I'm reviewing this now, but I wanted to make sure y'all knew that I needed to merge Going through the front end right now, and it is looking good. 😎 |
@roseeichelmann still reviewing but I caught one place where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested all of the UI with the admin role, and I only found one tiny change in the fatalities export config that I noted above. All else looks great and good to go! Happy to see all this work come together! 🙌 🎉
thanks, Mike! wanted to mention that i am also starting a review of this based on a full replica of prod that includes the change log tables 🧑🔬 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the issue Mike flagged, everything looks great to me. I think it would be good to merge main before we merge back, just for good measure.
🚢
I patched this, removed Mike's review request, and i'm merging it now |
Associated issues
Closes cityofaustin/atd-data-tech#19185
PR #1551 revealed that there is need for our data model to enable null user overrides to CRIS values. This PR is a proof of concept on the crashes tables that implements the 2 layer data model structure i proposed awhile back in the data model prototyping stage. There are only two tables, the
crashes_cris
table which only contains values straight from cris, and thecrashes
table which acts as the unified table that contains both cris values and user edits if there was a user override. This is the table that users will be updating. We are basically just nixing the whole_edits
layer.Testing
URL to test:
Local
Steps to test:
/vision-zero/etl/cris_import/extracts
then follow the test steps incris_import/README.md
to run the cris import docker image and run the following command to process those extract zips:change_log_crashes
andchange_log_crashes_cris
and make sure you are seeing your changes there as expectedShip list
main
branch