News for hackers. Stuff that matters.
Re:Git as a NoSql Database (2016) by simonw on Monday April 05, 2021 @05:27PM (#26704938)
In almost every database-backed application I've ever built someone, at some point, inevitable asks for the ability to see what changes were made when and by whom.

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.

Re:Git as a NoSql Database (2016) by lisper on Monday April 05, 2021 @05:53PM (#26705167)
> 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.

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.

Re:Git as a NoSql Database (2016) by zikzak on Monday April 05, 2021 @07:28PM (#26706015)
A developer joined a team I was on once. The boss was infamous for hiring anyone with a pulse and assigning a small client project. Sink or swim.

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".

Re:Git as a NoSql Database (2016) by com2kid on Monday April 05, 2021 @08:09PM (#26706353)
That is... almost not horrible?

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!

Re:Git as a NoSql Database (2016) by collyw on Tuesday April 06, 2021 @12:24PM (#26713843)
It's actually a decent hiring process providing the new hires are made aware of it in advance.
Re:Git as a NoSql Database (2016) by zikzak on Tuesday April 06, 2021 @02:34PM (#26715569)
He was a radical honestly type guy. It was all on the table and we had lots of success stories. We would give anyone a chance which let a lot of self taught, entry level people get work. I got a ton of experience mentoring people, as well (difficult people, too). Unfortunately, he got screwed over by a shotgun clause in a business agreement and lost the business that to an ex-partner. That's what led me to my current job, though, where I've been happy for over 10 years and it's much more stable.
Re:Git as a NoSql Database (2016) by dragonwriter on Tuesday April 06, 2021 @12:46PM (#26714146)
> "I store all dates in spreadsheets in ISO format"

As in SQL, the application’s native date format (which is usually a number with appropriate format) would be the natural choice and a YYYY-MM-DD string would be a distant second. ISO (presumably, 8601) format is too broad, and admits of a mix of formats that are not simply sortable (quick, which is first 2021-W14-2 or 2021-04-07?).

Re:Git as a NoSql Database (2016) by com2kid on Tuesday April 06, 2021 @01:19PM (#26714656)
Eh, when people say ISO they mostly mean YYYY-MM-DD.

If a date is going to be string prepended to something else, or if the spreadsheet is going to be exported to CSV, or parsed by some tool, then storing dates in YYYY-MM-DD can be a very justifiable thing to do in a spreadsheet.

Also Excel likes to format dates using the system locale, which is, well, stupid. So I have to enter YYYY-MM-DD as a custom format anyway, or change the locale on the column to China. (Or Cherokee, who apparently also properly format their dates!)

(Also Excel is smart enough if you set a column as YYYY-MM-DD custom format, it'll let you use all the date based pivot table stuff as expected)

Re:Git as a NoSql Database (2016) by pcr910303 on Monday April 05, 2021 @09:40PM (#26707045)
> I store all my dates in sql as text in iso format so I can easily sort them

Strong SQLite vibes... (SQLite doesn't have a date format, it has builtin functions that accept ISO format text or unix timestamps)

Re:Git as a NoSql Database (2016) by calvinmorrison on Tuesday April 06, 2021 @12:10AM (#26707870)
As a Unix person, aren't dates just number? Why is sort complex? Just parse input and render timestamps
Re:Git as a NoSql Database (2016) by yen223 on Tuesday April 06, 2021 @03:36AM (#26709122)
It's pretty miserable when you're trying to look up a date, and all you get are numbers that requires a conversion step to be readable.
Re:Git as a NoSql Database (2016) by drchickensalad on Tuesday April 06, 2021 @06:59AM (#26710392)
Assuming by number you mean epoch seconds/milliseconds, a number can store the instant in time, but not a TIMEZONE. Obviously you could do bit magic if you shift it over (so you don't mess up sorting), but that's true for any data and a sufficiently large number type.
Re:Git as a NoSql Database (2016) by adrianN on Tuesday April 06, 2021 @03:14AM (#26708985)
Time zone information makes this a bit tricky.
Re:Git as a NoSql Database (2016) by zikzak on Tuesday April 06, 2021 @02:36PM (#26715581)
That's a good point. We were talking MS SQL but yes, that would make way more sense.
Re:Git as a NoSql Database (2016) by beagle3 on Tuesday April 06, 2021 @03:41AM (#26709161)
I did that in DB2 or Oracle (or both, don’t remember - it was 15 years ago and the project used both) because I needed millisecond time resolution and the database date time field did not support milliseconds.

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.

Re:Git as a NoSql Database (2016) by hnarn on Tuesday April 06, 2021 @03:51AM (#26709219)
Surely you can do both, so you can still perform sane sorting/indexing on "real" timestamps and then use the extra precision string timestamp for drilling down?
Re:Git as a NoSql Database (2016) by beagle3 on Tuesday April 06, 2021 @07:37AM (#26710639)
Iso8601 sorts just as well.

I saw no benefit in storing two copies. That’s recipe for problems - e.g. “update” code that doesn’t update both, or somehow updates them differently (which one is right?). You can probably have t-sql or some “check” constraint to enforce equivalence, but ... why?

For most practical uses, an ISO8601 textual representation is as good, though a little less space efficient.

Re:Git as a NoSql Database (2016) by dragonwriter on Tuesday April 06, 2021 @12:52PM (#26714230)
> Iso8601 sorts just as well.

No, it doesn’t, since all of the following are valid ISO 8601 representations of a date:

20210408 2021-04-07 2021-W14-1 2021W143 2021-097 2021098

(Now, consistently using any one of the ISO 8601 formats is sortable...)

Re:Git as a NoSql Database (2016) by beagle3 on Tuesday April 06, 2021 @05:45PM (#26717752)
Point taken.

I always recommend and use the specific ISO8601 format

    YYYY-MM-DDThh:mm:ss.sssZ
(or drop the ".sss" if not needed), and be 100% consistent about it.

But you are right, I shouldn't refer to this as "use ISO8601" because it is only one of the numeous possible formats described by that spec.

Re:Git as a NoSql Database (2016) by lmm on Tuesday April 06, 2021 @12:36AM (#26707977)
Sounds like someone who's realised how crappy most databases' time handling is.
Re:Git as a NoSql Database (2016) by dmingod666 on Monday April 05, 2021 @11:05PM (#26707554)
I once saw an app that had a text column as date, then 3 other columns for day month and year so they could sort by date.
Re:Git as a NoSql Database (2016) by arethuza on Tuesday April 06, 2021 @06:14AM (#26710117)
I remember one design I reviewed that wanted to use XML as something to be queried using simple text comparison (this was before some databases adding explicit support for XML).
Re:Git as a NoSql Database (2016) by dmingod666 on Tuesday April 06, 2021 @09:36PM (#26719591)
Not XML, but, the classic 'never parse html with regex'

https://stackoverflow.com/questions/1732348/regex-match-open...

:)

Re:Git as a NoSql Database (2016) by chaps on Tuesday April 06, 2021 @12:16AM (#26707898)
Meh, I don't see much wrong with this honestly. There are some cases where using text as the type is the only way. Bet you the junior dev worked with a lot of messy data in the past, where it wasn't always possible to do a direct datestr -> SQL date type.

Just point him in the right direction and move on.

Re:Git as a NoSql Database (2016) by zikzak on Tuesday April 06, 2021 @02:42PM (#26715669)
Yeah, I did explain why that wasn't "how we did it", and tried not to sound like a know it all (I am definitely not this).

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.

Re:Git as a NoSql Database (2016) by chaps on Tuesday April 06, 2021 @06:21PM (#26718103)
Hah, amazing and thanks for sharing. I think it's mostly that you sounded like you were holding a petty grudge over some small technical thing that can make sense. Maybe he resigned because he felt overly judged?
Re:Git as a NoSql Database (2016) by zikzak on Wednesday April 07, 2021 @06:48PM (#26732543)
No, he had a day drinking and absentee problem. My boss talked with him, offered him another chance, but he resigned. He really didn't like following requirements either but I think it was just a symptom of his overall problems. He was going through something and we were just a stop on his journey.
Re:Git as a NoSql Database (2016) by chaps on Thursday April 08, 2021 @06:01PM (#26744376)
Fair enough. Cheers.
Re:Git as a NoSql Database (2016) by qmmmur on Monday April 05, 2021 @08:19PM (#26706449)
Why is this bad?
Re:Git as a NoSql Database (2016) by happythought on Monday April 05, 2021 @08:33PM (#26706571)
Sql databases usually come with their own date types that are implemented with integers behind the curtains. They take up less space and are easier to sort than text fields.

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.

Re:Git as a NoSql Database (2016) by deathanatos on Monday April 05, 2021 @09:45PM (#26707077)
But which very likely store less information than an ISO timestamp does. (The integers stored are usually POSIX timestamps.) So, you might have to store, e.g., timezone information elsewhere. (And that might also be a good thing. It might not. It depends. Without knowing more, the DB's type is probably the right choice.)

I've seen far worse things than this done to a SQL database though…

Re:Git as a NoSql Database (2016) by zachrose on Monday April 05, 2021 @10:38PM (#26707400)
Except that ISO-8601 doesn’t include anything as useful as a political time zone, just an offset from UTC. That’d be good if UTC offset was useful for anything, but instead it just adds to the confusion.
Re:Git as a NoSql Database (2016) by zachrose on Wednesday April 07, 2021 @10:26AM (#26725434)
A lot of this was really cleared up for me by Evan Czaplicki's documentation for the Elm time library: https://github.com/elm/time
Re:Git as a NoSql Database (2016) by chillfox on Tuesday April 06, 2021 @01:03AM (#26708098)
UTC offset is way more useful than those 3-4 character timezone abbreviations.

Just have a look at the list from Wikipedia [1] and notice how many repeats there are.

As an example AMT could be either UTC+4 or UTC-4.

And this doesn't even includes the various local acronyms that people use around the world.

[1] https://en.wikipedia.org/wiki/List_of_time_zone_abbreviation...

Re:Git as a NoSql Database (2016) by hobs on Tuesday April 06, 2021 @10:46AM (#26712426)
I didn't downvote you, but just for reference the time zone abbreviations you are supposed to use are in the tzdata db, and are listed https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

If you don't use these, you will inevitably be somewhat wrong due to leap issues, political changes in time, or the like.

Re:Git as a NoSql Database (2016) by hashhar on Tuesday April 06, 2021 @02:53AM (#26708837)
Political zones are not the same thing as the abbreviated zones.

IANA time zone identifiers are fully-qualified and unambiguous like America/Los_Angeles or Asia/Kolkata.

Re:Git as a NoSql Database (2016) by chillfox on Tuesday April 06, 2021 @04:19AM (#26709396)
Thanks, I have never heard the term “political zones” before, so I made an assumption.
Re:Git as a NoSql Database (2016) by golergka on Tuesday April 06, 2021 @05:49AM (#26709967)
At least in Postgresql, it is standard practice to use timestamptz type, which saves timestamp together with a time zone. Not only it uses less space on disc, but you can do a lot of operations with it natively in database itself: sort in various ways, compare to NOW(), construct time intervals and even ensure data validity with checks.
Re:Git as a NoSql Database (2016) by singron on Tuesday April 06, 2021 @07:14AM (#26710481)
Timestamptz doesn't store a time zone in postgres. It converts all timestamps to utc. It's a common misconception.
Re:Git as a NoSql Database (2016) by dragonwriter on Tuesday April 06, 2021 @12:58PM (#26714329)
> But which very likely store less information than an ISO timestamp does.

If you are trying to store dates and not timestamps, that’s what you want, otherwise equality tests might not work right.

> (The integers stored are usually POSIX timestamps.)

For date types, if they exist distinctly, usually not.

Re:Git as a NoSql Database (2016) by Something1234 on Monday April 05, 2021 @08:34PM (#26706581)
I'm going to guess because sql has rich datetime support. At least the majority of modern databases do.
Re:Git as a NoSql Database (2016) by dmingod666 on Monday April 05, 2021 @11:08PM (#26707575)
You can then do things like greater than date or between X date and y date and get some use out of that column..
Re:Git as a NoSql Database (2016) by swiley on Monday April 05, 2021 @08:42PM (#26706644)
ITT HN collectively learns what an "audit log" is.
Re:Git as a NoSql Database (2016) by harperlee on Tuesday April 06, 2021 @04:16AM (#26709374)
That reminds me of https://www.enterpriseready.io/ where you can find a guide of which features, such as an audit log, you may not have though about when building your side project, B2C startup, etc. that will facilitate its uptake by companies.

For example, for audit logs: https://www.enterpriseready.io/features/audit-log/

Re:Git as a NoSql Database (2016) by antonvs on Tuesday April 06, 2021 @01:37AM (#26708261)
I would imagine the functional programming advocates here already understand this. For the rest, audit logs are at least a baby step towards that. Progress!
Re:Git as a NoSql Database (2016) by acidbaseextract on Monday April 05, 2021 @06:56PM (#26705718)
Completely agreed on the inevitability of that ask.

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.

[1] https://debezium.io/

Re:Git as a NoSql Database (2016) by Aqueous on Monday April 05, 2021 @07:37PM (#26706096)
usually businesses use auditing tables to track this, usually by setting up triggers to insert a row into the auditing table any time a delete, update or insert occurs on the original
Re:Git as a NoSql Database (2016) by sedeki on Monday April 05, 2021 @05:38PM (#26705037)
So each commit is exactly one change to a relevant table?

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.

Re:Git as a NoSql Database (2016) by irrational on Monday April 05, 2021 @06:58PM (#26705738)
So you commit to Git.

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.

Re:Git as a NoSql Database (2016) by simonw on Monday April 05, 2021 @10:17PM (#26707268)
You report it could have been Sally or Billy
Re:Git as a NoSql Database (2016) by irrational on Tuesday April 06, 2021 @12:15PM (#26713721)
That isn’t how this works. Based on OPs description, the fact that Sally made a change is gone since the last editor was Billy. It looks like Billy made the change to both column 1 and 2.
Re:Git as a NoSql Database (2016) by simonw on Tuesday April 06, 2021 @12:55PM (#26714293)
You tell your boss:

"Just so you know, we only take a snapshot every X minutes... so there's a chance Billy wasn't the person who made that change. If you had told me you were planning to fire people as a result of this tracking system I might have spent more than five minutes hacking it together with a cronjob and a git repository."

Re:Git as a NoSql Database (2016) by TeeMassive on Monday April 05, 2021 @08:41PM (#26706635)
Your boss let changes go through the production DB directly

Your boss decides to fire people as a solution

Your boss should be fired

Re:Git as a NoSql Database (2016) by livvelupp on Monday April 05, 2021 @09:19PM (#26706930)
Your boss doesn't micro manage

You should be taking care of this, not Billy

Re:Git as a NoSql Database (2016) by TeeMassive on Monday April 05, 2021 @09:42PM (#26707056)
Firing a team member for a team mistake is micromanagement.
Re:Git as a NoSql Database (2016) by irrational on Tuesday April 06, 2021 @12:13PM (#26713693)
I’m assuming Billy was fired because Sally made an unethical or illegal change.
Re:Git as a NoSql Database (2016) by antonvs on Tuesday April 06, 2021 @01:39AM (#26708269)
Billy did nothing wrong!
Re:Git as a NoSql Database (2016) by irrational on Tuesday April 06, 2021 @12:13PM (#26713679)
I’m assuming the change Sally made was an unethical or illegal change.
Re:Git as a NoSql Database (2016) by simonw on Monday April 05, 2021 @10:21PM (#26707293)
Since this is being picked apart a bit in the comments, I should clarify that I don't think this is the BEST solution to this problem. It's the solution that gives you 90% if the value with 5% of the work.
Re:Git as a NoSql Database (2016) by dragonwriter on Tuesday April 06, 2021 @12:34PM (#26713961)
> It's the solution that gives you 90% if the value with 5% of the work.

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.

Re:Git as a NoSql Database (2016) by vishnugupta on Tuesday April 06, 2021 @02:00AM (#26708423)
A running joke at Uber is that every single configuration management system will end up re-implementing a half ass version of Git.
Re:Git as a NoSql Database (2016) by bitwize on Tuesday April 06, 2021 @01:11PM (#26714505)
Were their exact words "an ad hoc, informally specified, bug-ridden, slow implementation of half of Git"?
Re:Git as a NoSql Database (2016) by vishnugupta on Wednesday April 07, 2021 @04:16PM (#26730577)
Heh something to that effect. I’m not at Uber anymore so can’t reference the article which makes this assertion. It is quite well written, starts off with a super simple version of configuration management system and describes how it progressively evolves to encompass 80% of Git features.
Re:Git as a NoSql Database (2016) by gjvnq on Monday April 05, 2021 @10:48PM (#26707454)
Why not have a history table and use SQL triggers to insert the new data as JSON everytime someone changes something?
Re:Git as a NoSql Database (2016) by coolgeek on Wednesday April 07, 2021 @07:39PM (#26733076)
Indeed. I have on multiple occasions written scripts to automatically generate the triggers and audit tables