-
Notifications
You must be signed in to change notification settings - Fork 2
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
tweak: Drop external foreign key constraints during GTFS import #1030
tweak: Drop external foreign key constraints during GTFS import #1030
Conversation
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 don't have a problem with the implementation as written, but how hard would it be to write tests for this functionality? If it's not to much effort, I think it'd be worthwhile to have.
@Whoops Sounds good, would testing the functions in The latter is a bit more challenging in its current state, since it's hardcoded to act on the GTFS tables specifically, but I should be able to tweak it to be more testable. |
I think |
Summary of changes
Asana Ticket: No ticket, followup to GTFS import feature
In order for
TRUNCATE all_the_gtfs_tables
to be possible, the tables need to have no dependent foreign key constraints originating from outside the set of tables being truncated.This achieves that by temporarily dropping such constraints, and then re-adding them after the GTFS tables have been repopulated.
Implementation notes
I wanted to make sure any Arrow -> GTFS foreign key constraints added in the future would be handled automatically by this logic.
I felt it would be too cumbersome for developers to have to remember to update code in two different places only when adding foreign keys satisfying these specific conditions.
As a result the code relies on some introspection tools provided by Postgres and is a bit heavy on custom queries, but I think it's still relatively straightforward, and worth it for the ease of use it provides.
Reviewer Checklist