"Human beings are born with different capacities. If they are free, they are not equal. And if they are equal, they are not free."
— Aleksandr Solzhenitsyn
I spent the whole of last week (wk33) on holiday in Herne Bay. While I did bring my laptop with me, I didn't make much use of it beyond playing Minecraft for a few hours.
This week at work I have jumped back into working on our growing mono-repo which means more TypeScript and Prisma.js fun. Speaking of Prisma, there was activity on issue #5006: Support
0000-00-00 00:00:00 for MySQL with two people providing similar solutions to the problem of Prisma.js crashing on MySQL zero dates.
The first approach by ChrisM3y is using a
preManipulationHook function to set any zero dates to
now(). There are three key problems with this approach:
preManipulationHookmust be run before each
SELECTquery on a problematic table adding overhead
- A zero date value can be considered as unset, setting it to an arbitrary value errases that information
- The date column can have importance, a zero date for the column
booked_in_atcan mean the booking has yet to be made, updating that to an arbitrary value will cause undesirable side effects
The second and most recent solution provided by bjih1999 invokes the usage of MySQL generated columns to create a virtual column that is
This is an eloquent solution to the problem, not ideal but good as a stop-gap measure; however, the problem of having zero date fields largely raises its ugly head in large legacy databases, these tend to have a lot of rows to which any alterations to the schema comes at a cost of locking the table for a period of time - therefore often is the case that schema changes have to go through approval processes and be planned to ensure downtime is either mitigated or constrained.
Joke of the week
"Why didn’t Han Solo enjoy his steak dinner? It was Chewie."
Notable Articles Read
- Should I use Signed or Unsigned Ints In C?
- Oberon: The tiniest but richest FOSS HLL and OS you've never heard of