|
|
|
|
|
by thatjoeoverthr
1387 days ago
|
|
Your database is is the state of your system. Guard it! I just ran into severe data corruption at a large client because a programmer four years ago wrote an empty catch block. The system would open a transaction, hit a fault, roll back, then continue writing to the database as if it’s still in the context of the transaction. I spent some time trying to pin down exactly what it did, and found that many writes went through because of a missing foreign key constraint. In short: if a particular table of minor importance had a foreign key constraint, there would have been no damage whatsoever, because it would have faulted immediately after the rollback. You can’t rig up a constraint against every dumb write. But you can rig them up against some of the dumb writes. And sometimes that’s enough. |
|
For that reason having constraints enforced by the system that stores the data, external to the app code which developers will inevitably mess up, is so useful and important.
So many issues in my experience have been similar to the one you describe. If the right constraints had been present so much work and so many headaches could have been avoided.
I feel like people who claim they're not needed or not important or "the app code will do it" need to be wrangled into maintenance work of old systems for a year or two until they repent. Rather than boshing out an ill-considered prototype and then moving on before the bugs are discovered.