Bad ideas - No referential integrity? Cascade orphans vs plugging orphans
Cascading deletes in RI prevent orphans.
From a recent migration:
# Kill orphaned payment methods... they DO exist :(
execute "delete from payment_methods where user_id is null"
Since we have no proper cascading deletes at the DB level, this just pushes the problem upstream while deleting valuable historic data. In other words, now we have orphaned orders with respect to payment methods.
If Kaiser Healthcare taught me one good trick, it's that if you're not using RI and you encounter orphaned relationships, plug the holes, don't remove the holes by sandblasting a bigger hole. Update orphans with a specific row that identifies them. Next time make a User with a first name "WARNING:ORPHAN" and assign it to all the orphaned payment methods.


Comments [0]