Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You'll have to rip the ability to generate unique numbers from quite literally anywhere in my app and save them without conflict from my cold, dead hands.

The ability to know ahead of time what a primary key will be (in lieu of persisting it first, then returning) opened up a whole new world of architecting work in my app. It made a lot of previous awkward things feel natural.





Sounds like a lot of referential integrity violations.

Why would generating a PK ahead of time cause referential integrity violations? Super curious to find out.

The implication is that you need to know the PK ahead of time so that you can insert it into other tables which reference it as an FK without waiting for it to be returned, which further implies that you don’t have FK constraints, because the DB would disallow this.

Tbf in Postgres, you can declare FKs to be deferrable, so their existence is checked at transaction commit, rather than at insertion time.

If you don’t have the DB enforcing referential integrity, you need to be extremely careful in your application logic; IME, this inevitably fails. At some point, someone writes bad code, and you get data anomalies.


> Tbf in Postgres, you can declare FKs to be deferrable, so their existence is checked at transaction commit, rather than at insertion time.h further implies that you don’t have FK constraints, because the DB would disallow this.

I'm using EF core which hooks up these relationships and allows me to persist them in a single transaction using MSSQL server.

> If you don’t have the DB enforcing referential integrity

I'm building an electronic medical system. I'm well aware of the benefits of referential integrity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: