Live data from Hacker News

Ask HN: How do you version control a Database?

news.ycombinator.com

11–16 of 16 posts

Re: Ask HN: How do you version control a Database?

#12

Earlier quoted context omitted.

I think diff is OK as a verification check after a deployment. But diff is not OK to generate the change script itself. It's not about abusing the diff. It's about diff being fundamentally the wrong technique to transition from state (C)urrent -> (T)arget. A diff cannot always bring you to the desired T. The diff only factors in 2 states (C and T) and not X,Y,Z which you may have an import from and which may need to…

I agree you may have a few transitional states to go through before dev becomes production. And in general, we didn't let the migration tools write our scripts for us, we used them to automate the testing and deployment of our scripts, maybe that is the key difference in how we used them. Which is maybe why I have never experienced what you are saying, when we added the tools in place, properly set things up and used…

Ty for the share.

Re: Ask HN: How do you version control a Database?

#15
post #3

If one of the many schema migration solutions out there doesn't work for you, hacking one together is simple enough: * Put your schema/data migrations into .sql files as raw SQL * Number the files from 0001 on * Write a script to apply each migration file to the DB in order, recording the file name to a log table after successful application. Only apply migrations not found in the log table. * Commit your .sql migrat…

That's a good approach - I've used it in a legacy system, although I named the files in the format "TIMESTAMP_migration_description", which is a bit more descriptive.
Post reply on HN