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?
Ask HN: How does your development team handle database migrations?
11–20 of 150 posts
Re: Ask HN: How does your development team handle database migrations?
#12To 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?
#13For 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?
#14Re: Ask HN: How does your development team handle database migrations?
#15You basically write SQL queries for up and down.
Re: Ask HN: How does your development team handle database migrations?
#16Re: Ask HN: How does your development team handle database migrations?
#17Re: Ask HN: How does your development team handle database migrations?
#18Re: Ask HN: How does your development team handle database migrations?
#19Re: Ask HN: How does your development team handle database migrations?
#20Besides that, I tend to follow the same general principals RainforestHQ presented in 2014 https://www.rainforestqa.com/blog/2014-06-27-zero-downtime-d...