by simonw · 5y ago · 0 comments
My current preferred strategy for dealing with this (at least for any table smaller than a few GBs) is to dump the entire table contents to a git repository on a schedule.
I've run this for a few toy projects and it seems to work really well. I'm ready to try it with something production-scale the next time the opportunity presents itself.
How does that solve the problem? All this would do is give you snapshots of the state of the DB at particular points in time.
The only way to know who changed what when is to keep track of those changes as they are made, and the best way to do that is to stick the changes in an eventlog table.
As the senior dev it was my job to provide info as needed and subtly assess the new, potential rockstar code ninjas.
Anyway, this new guy says "I store all my dates in sql as text in iso format so I can easily sort them".
If he had said anything other than "in sql" it would be the correct answer.
"I store all dates in spreadsheets in ISO format"
"I prepend ISO dates to marketing campaign names so I can easily sort them in the horrible web frontends that doesn't have a sort by date option"
"I start all my blog entries with ISO dates..."
I mean, just... so close!
Strong SQLite vibes... (SQLite doesn't have a date format, it has builtin functions that accept ISO format text or unix timestamps)
Among the option of storing (date field, millisecond field) and (date as iso8601 text field with millisecond without time zone) I chose the latter, and I can’t tell for sure but it was almost surely the better choice.
Just point him in the right direction and move on.
I am way less judgemental now and a lot of the comments here are making me rethink what I thought about him saying this. He had a lot of other issues and resigned after a couple of days so I guess we'll never know what he was capable of.
EDIT: also I wouldn’t consider this egregious. If the Senior explains and the person was happy to learn something then that’s a good outcome. If they are stubborn about it, then that wouldn’t be great.
For example, for audit logs: https://www.enterpriseready.io/features/audit-log/
At risk of extreme overkill the other way, something like Debezium [1] doing change monitoring dumping into S3 might be a viable industrial strength approach. I haven't used it in production, but have been looking for appropriate time to try it.
I guess you can't just plug this into a common system of rotating logs easily, as there might be several changes beteeen the log rotation.
Also, I guess you'd need a user friendlier interface to actually display who made the change from the git repo.
Anyway, interesting solution.
Sally makes a change to column 1 of record 1.
Billy makes a change to column 2 of record 1 a nanosecond later.
You commit to Git again.
Your boss wants to know who changed column 1 of record 1.
You report it was Billy.
Billy is fired.
Your boss decides to fire people as a solution
Your boss should be fired
You should be taking care of this, not Billy
It’s not, though. History tables don’t provide only 111% of the value of this, and don’t take 20× the effort. They have a deterministic relation to base tables (so generating the schema from that of base tables, and the code necesaary for maintenance, is a scriptable mechanical transform if you have the base table schema.)
OTOH, lots of places I've seen approach this by haphazard addition of some of what I think of as “audit theater” columns to base tables (usually some or all of “created”, “created_at”, “last_updated”, “updated_by”), so its also not the worst approach I’ve seen.