mbucc / shmig

Database migration tool written in BASH.
BSD 3-Clause "New" or "Revised" License
458 stars 49 forks source link

Add config item for date format #42

Closed kael-shipman closed 6 years ago

kael-shipman commented 6 years ago

I prefer human-readable timestamps in files, so it would be great to have a config item that can be used as the source for timestamp generation. Something like TIMESTAMP_FORMAT="%Y%m%d-%H%M%S" (which, of course, the user could alter in any way s/he chooses).

I think the only hiccup this presents is in finding migration files, HOWEVER, I believe that it may be considered safe to assume that any *.sql files in the migrations directory can be considered to be migrations. You might argue that you could also store init and seed files in your migrations directory, but I would counter that that's probably not great system design and you should instead of have a hierarchy that includes migrations as a subdirectory of a db directory.

Anyway, I'm exploring implementing this now in my own human-timestamps branch, but am backlogged at work, so probably won't get to it as soon as I'd like. Please comment so I can implement something that you're happy enough with to merge ;).

kael-shipman commented 6 years ago

I just decided to dig into this anyway and discovered that it may be more disruptive to your work than I had hoped :(. I found out that you're currently storing versions as integers in the db, and furthermore, you're padding them to 10 characters. While I think a switch to varchar/text from integer is innocent enough, I couldn't find a good function right off (in all databases) to guarantee successful lexical sorting in the event that the unix timestamp gets longer by a digit.

That said, that won't happen for quite some time...... Open to solutions either way.

kael-shipman commented 6 years ago

@mbucc any thoughts on this?

mbucc commented 6 years ago

This came up before (issue #32). I prefer epoch seconds because they represent a timezone. Also, a human readable date format is in the first few lines of the generated file.

I suppose an option to list migrations that converted the timestamp on the file name to a human readable format would be useful.

kael-shipman commented 6 years ago

I'll close this in favor of #32, but I'm going to leave some comments there ;).