News for hackers. Stuff that matters.
Re:We do not use foreign keys (2016) by hrktb on Friday November 08, 2019 @05:05PM (#21487358)
It’s at its core a case by case decision, I think FK are also a net negative in data ingestion scenari where the data set is big enough.

Trying to make sure everything is where it needs to be at any given time, everything is inserted in the right order and the data is always consistent brings exponential amount of conplexity when it could all be checked at the end and pruned for invalid data. And usually DB integrity will not be enough, you’ll want business level validation that all is OK, so there will be app level checks anyway.

Re:We do not use foreign keys (2016) by joevandyk on Friday November 08, 2019 @10:06PM (#21489313)
PostgreSQL supports deferring constraints. https://begriffs.com/posts/2017-08-27-deferrable-sql-constra...
Re:We do not use foreign keys (2016) by hrktb on Saturday November 09, 2019 @03:56AM (#21490448)
This looks nice, it’s still limit to a single commit though. That’s where it’s a PITA for anything that won’t (or we don’t want to) fit a single commit.

In particular splitting commits allows to ingest data in parralel (for instance if we import stores and store owners, both could be ingested separately without caring at first if each references a valid entity)

Re:We do not use foreign keys (2016) by JoshuaDavid on Saturday November 09, 2019 @07:01AM (#21491015)
At least with mysql, and probably with postgres as well, you can temporarily turn off foreign key checks for a set of statements. So you can still get the benefits of foreign key constraints by default but when they do more harm than good you can turn them off. With the added benefit that turning off FK constraints screams "I am doing something unusual and dangerous - this requires extra caution."
Re:We do not use foreign keys (2016) by sturgill on Friday November 08, 2019 @10:58PM (#21489482)
App level data integrity is usually critical. Ingestion into a reporting database is an entirely different construct (where I agree FK constraints are burdensome).