Live data from Hacker News

Ask HN: How does your development team handle database migrations?

news.ycombinator.com

11–20 of 150 posts

Re: Ask HN: How does your development team handle database migrations?

#11
post #10

At my previous job we either didn't migrate and wrote application level transforms that would update records as they were encountered by users (mongodb) or we had a custom built migration system that ran JavaScript snippets on our shards. The migration system was miserable to work with and it was hard to debug the code on stage in such a way that would allow us to anticipate whatever might be on prod...

This sounds like a nightmare. Why?

>(mongodb)

Re: Ask HN: How does your development team handle database migrations?

#12
We use the RedGate SQL compare tools [1] to compare our new schema to our old one and auto-apply the diffs to the production DB (this is done automatically by our deployment process).

To reduce the chance of error we don’t destroy columns or tables.

Our application then has an update step which runs on startup for any data migrations (or new data additions), and then updates a version number stored in the DB. The data migrations are super rare.

This all means we can migrate from any past version to our latest one: because we have all previous schemas stored in git and n update functions in our app that can walk the versions

It’s worked reliably for over a decade and is pretty much entirely pain free

[1] https://www.red-gate.com/products/sql-development/sql-compar...

Re: Ask HN: How does your development team handle database migrations?

#13
Depends on the database, in my opinion. Each one has quirks to be mindful of, depending on the amount of data you're migrating/touching.

For example, if you accidentally put a 'default' on a column when you add it to postgres, it will lock the entire table while it rewrites every row, inserting that default value.

Another common postgres blunder is creating indexes on big tables without using 'concurrently'. This also locks the table for writing and you'll have a bad time.

Re: Ask HN: How does your development team handle database migrations?

#20
I don't think there is a way to change the database without slowing down development. After all, the data is the most valuable thing you have.

Besides that, I tend to follow the same general principals RainforestHQ presented in 2014 https://www.rainforestqa.com/blog/2014-06-27-zero-downtime-d...

Post reply on HN