News for hackers. Stuff that matters.
Re:Database schema changes are hard (2017) by jayd16 on Friday March 01, 2019 @11:15PM (#19287533)
The reason you keep a migration chain is so you have a clear path from anything in the wild to the latest. Unless I'm misunderstanding, throwing this away means you need to migrate some unknown permutation to latest.

The hardest part of the migration is migrating the data and as far as I can tell that is glossed over.

Why is throwing away the iterative migration version useful exactly?

Re:Database schema changes are hard (2017) by jarnagin on Saturday March 02, 2019 @02:32AM (#19288094)
Moreover, Django already has facilities for compacting migration files together: squashing.

https://docs.djangoproject.com/en/1.9/topics/migrations/#mig...

Re:Database schema changes are hard (2017) by wvenable on Friday March 01, 2019 @11:46PM (#19287620)
I agree but I also have migrations that don't correspond to any release of the product. You need to run a migration to update your database so you can test your changes. A single product release might contain hundreds of migration files; maybe some that simply undo the affect of some previous migration. The pain of that is real but your point is valid.

I like this product but I agree that it doesn't solve all migration issues. I do think we need better migration tools.

Re:Database schema changes are hard (2017) by Existenceblinks on Saturday March 02, 2019 @03:05AM (#19288196)
In theory yes, but I've barely looked at those old migration files even the latest one. Barely rollback, just patch with a new one. Some people say a rollback is just another migration "up"
Re:Database schema changes are hard (2017) by djrobstep on Friday March 01, 2019 @11:27PM (#19287568)
In many (most?) cases people have a single production environment.

If you have multiple versions in the wild to support, there's nothing stopping you from supporting multiple upgrade paths, or even continuing to chain migration files, if you want to.

Moving data about is always going to be a manual process. This approach just helps you test it better.

Re:Database schema changes are hard (2017) by recursive on Saturday March 02, 2019 @01:14AM (#19287881)
You just got done telling me that migrations are bad, but also the solution to some non-trivial deployment scenario is to just continue using migrations?

> Moving data about is always going to be a manual process.

No, it's not always.

Re:Database schema changes are hard (2017) by djrobstep on Saturday March 02, 2019 @02:03AM (#19288010)
Did you even read it? No idea where you got "migrations are bad" from.

If moving data around within a migration isn't always a manual process, please show me the tool which automatically generates the correct statements.

Re:Database schema changes are hard (2017) by recursive on Saturday March 02, 2019 @10:28AM (#19289577)
I don't believe a tool can always generate the correct statements. But I do believe those same statements can be used on all deployments, which I consider automation.
Re:Database schema changes are hard (2017) by mdonahoe on Friday March 01, 2019 @11:43PM (#19287611)
What about apps running on users’ devices, with their own internal databases for local storage?

When a user on random old version finally updates their app to latest, that latest code better be able to handle a migration correctly.

Re:Database schema changes are hard (2017) by simonw on Saturday March 02, 2019 @11:15AM (#19289778)
I don't buy this at all. It may be true for projects with only a single developer, but consider environments with a larger team.

First, every developer has a development environment. If someone goes on holiday for a few weeks they will come back to a personal environment that's likely several steps behind everyone else.

Smart engineering orgs have one or (hopefully) more QA environments which differ from production by design - they're where you preview and test upcoming features that may involve schema changes.

At a certain scale individual teams may have their own dedicated QA environments, for testing in-development features without disrupting the work of other teams.

Then there are environments for running integration tests, hooking up to CI systems, load testing etc.

There may be only one production environment but there could be dozens or even hundreds of other environments that need to be able to reliably apply migrations up to a specific point.

The Django approach to migrations handles this really well.

Re:Database schema changes are hard (2017) by djrobstep on Saturday March 02, 2019 @03:45PM (#19291085)
? None of those are production environments.
Re:Database schema changes are hard (2017) by simonw on Saturday March 02, 2019 @05:52PM (#19291615)
They're "production" in as much as they need to work. They still need to have migrations applied to them in an automated and repeatable way.
Re:Database schema changes are hard (2017) by djrobstep on Saturday March 02, 2019 @06:53PM (#19291872)
"An environment that needs to work" is not what "production environment" means.
Re:Database schema changes are hard (2017) by jayd16 on Friday March 01, 2019 @11:42PM (#19287608)
I would say this is a pretty limited view. If you're working on a large team with many non production environments, this style is far more cumbersome than the upgrade chain method.

If we're talking about deployed sqlite dbs running on client machines, expecting an upgrade to be a manual process is simply not acceptable.

Re:Database schema changes are hard (2017) by djrobstep on Friday March 01, 2019 @11:59PM (#19287649)
What makes it more cumbersome?
Re:Database schema changes are hard (2017) by jayd16 on Saturday March 02, 2019 @12:04AM (#19287668)
If I'm understanding correctly, the suggestion is to run the migration by hand and handle issues as they arise. Not nearly as nice as an automated migration.
Re:Database schema changes are hard (2017) by djrobstep on Saturday March 02, 2019 @03:13AM (#19288223)
The talk is more about creation migration scripts than deploying them, but definitely not suggesting doing anything by hand. The idea is to ensure correctness so you can automate the deployments with confidence.
Re:Database schema changes are hard (2017) by twic on Saturday March 02, 2019 @08:27AM (#19289147)
> In many (most?) cases people have a single production environment.

No idea why this was downvoted, because this is a key truth.

You need to be able to migrate the production database to the latest version without losing any data.

You need to be able to replace any non-production database with the same schema as production. Ideally, with a (sanitised, subsetted, etc) copy of its data.

You don't need to be able to do anything else.

Re:Database schema changes are hard (2017) by akx on Saturday March 02, 2019 @09:31AM (#19289398)
You're only thinking about SaaSy things there.

What about on-premises or just open-source software, where you any number of any version of your software may be installed around the universe, and those users need to upgrade to a newer version?

Re:Database schema changes are hard (2017) by simonw on Saturday March 02, 2019 @11:17AM (#19289780)
See my comment here about organizations with many engineers and teams: https://news.ycombinator.com/item?id=19289778
Re:Database schema changes are hard (2017) by gpm on Saturday March 02, 2019 @12:28AM (#19287745)
Backups...