Ask HN: How do you do database version control, deployments, etc?
I'm working on a side project and I want to deploy the application to production as soon as possible, but I'm dreading having to deal with deploying schema changes, testing database deployments and everything else. In the past I've rolled my own primitive deployment scripts and database versioning scheme, but I'm wondering if there is a more robust solution out there. Is there a solid CD or CI solution out there for databases?
15 comments
[ 3.2 ms ] story [ 46.3 ms ] threadI too find it useful to keep the migrations small and succinct. For Oracle do migrations where the DDL cannot be rolledback I choose to separate these from straight data manipulation.
A downside to the project that I see is that although it’s quite mature the author is very very slow to engage with open source modifications.
I’d still make it my first choice because of its simplicity.
Simply put the DB isn't code, and a DB changes are in another category when looking at the risks involved. Deploying to your own MYSQL cluster vs AWS vs Postgres vs oracle are all very different mindsets, tools and requirements.
Can you get away with a tool in the short term, probably - and it would be one specific to the language you work in. Pick something your side project is written in, or something your interested in learning if your willing to go higher risk.
For small changes, we use scripts 'INSTALL_[SCHEMA].sql' and 'ROLLBACK_[SCHEMA].sql' which do everything needed including backups / restores of any tables needed.
This is tested in the DEV/QA environments as needed then run in Prod right before deploying the application changes.
We haven't had high availability requirements and can get away with a scheduled 3 minute outage but this works for us.
The beauty is that if something goes wrong, the rollback script gets us out of trouble.
ah, would it be that were true. Suppose you need to roll back until after the next install? I defy you to set up a reliable test plan that will handle the usual series of casual database tweaking popular with modern devs. The time spent developing and assuring the quality of the rollback will be mostly wasted energy when you're faced with rolling back a change which the next N changes are dependent on.
(more) seriously any sane scheme like yours seems to run into trouble when people want to add columns to some base table. Thusly I think "Alter Table" should be a banned operation for devs in any live system. But it's great job security for a DBA (speaking as a DBA, btw).
Is your CI environment a FULL CLONE of your production environment?
Lets take a look at the mysql manual for a second:
https://dev.mysql.com/doc/refman/5.7/en/alter-table.html#alt...
Not every operation can be done "in place" if you have a high traffic table with 100MM records in it, can you run that alter without taking downtime? Where is the safety valve that stops your day one rookie from forcing a down time if you have a CD process?
CI/CD is suposed to be creating a safety net, not a way to push a massive screwup into production faster!
There isn't a magic tool that is going to make this easy, because every environment is different... RTFM for all your tools and figure out what works for you if "by hand" isn't going to cut it and build that.
Flywaydb doesn't cover db testing.