In #1265, we marked a GBFS feed as deprecated if it was removed from systems.csv.
However, our actual intent is to fully remove the feed from the database in that case.
Just deleting the feed with session.delete(gbfs_feed) does not work because of constraint that prevent deletion of a Feed if it's present in the externalid table.
Intially we tried:
gbfs_feed.externalids.clear()
session.delete(gbfs_feed)
This worked temporarily, but only because our test feeds didn’t have all the relationships (e.g., entitytypefeed) that production feeds do. Moreover, this approach is fragile because it relies on the Python code being aware of all database constraints and relationships.
We also tried modifying database.py to augment cascade_entities, but it didn’t have the desired effect.
but it worked only because the test feeds we were using did not have all the relationships a production feed has (e.g. the entitytypefeed). Also this code is not very good because it assumes the python code is aware of all the constraints.
We tried modifying database.py to augment cascade_entities, but it did not work.
Ultimately, we got the deletion working using the following Liquibase change:
ALTER TABLE ExternalID DROP CONSTRAINT IF EXISTS externalid_feed_id_fkey;
ALTER TABLE ExternalID
ADD CONSTRAINT externalid_feed_id_fkey
FOREIGN KEY (feed_id) REFERENCES Feed(id) ON DELETE CASCADE;
This solves the problem only for the feed.externalids relationship. We now need to review the database schema and apply similar ON DELETE CASCADE logic to all relationship tables where the data doesn't make sense without the referenced Feed.
In #1265, we marked a GBFS feed as deprecated if it was removed from
systems.csv.However, our actual intent is to fully remove the feed from the database in that case.
Just deleting the feed with
session.delete(gbfs_feed)does not work because of constraint that prevent deletion of a Feed if it's present in the externalid table.Intially we tried:
This worked temporarily, but only because our test feeds didn’t have all the relationships (e.g.,
entitytypefeed) that production feeds do. Moreover, this approach is fragile because it relies on the Python code being aware of all database constraints and relationships.We also tried modifying
database.pyto augmentcascade_entities, but it didn’t have the desired effect.but it worked only because the test feeds we were using did not have all the relationships a production feed has (e.g. the entitytypefeed). Also this code is not very good because it assumes the python code is aware of all the constraints.
We tried modifying database.py to augment
cascade_entities, but it did not work.Ultimately, we got the deletion working using the following Liquibase change:
This solves the problem only for the
feed.externalidsrelationship. We now need to review the database schema and apply similarON DELETE CASCADElogic to all relationship tables where the data doesn't make sense without the referenced Feed.