Re:Ask HN: How do you version control a Database?
by lastofus on Monday July 20, 2015 @01:25PM
(#9917554)
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 migration files along with the code it is tied to.
Re:Ask HN: How do you version control a Database?
by guh_me on Friday July 24, 2015 @08:37PM
(#9946067)
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.
* 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 migration files along with the code it is tied to.