Re:When deployments are easy, code becomes simpler
by steffres on Wednesday September 06, 2023 @05:21AM
(#37402917)
I didn't mean to use Django _and_ a separate migration tool. It's just that I did work with Django so far, but switching now to a new codebase without it. Hence my question for experiences in DB migration.
Re:When deployments are easy, code becomes simpler
by azlev on Wednesday September 06, 2023 @06:10AM
(#37403207)
At work we use Django migrations. It helps. But the core of schema evolution is backward compatibility. To reach this goal, code review is necessary.
Here we never drop columns, only add new colunms, also never change column types.
When it comes to constraints (not null or something else) we double check about backwards compatibility.
Changing data is not a robust rollback.
Re:When deployments are easy, code becomes simpler
by robertlagrant on Wednesday September 06, 2023 @05:16AM
(#37402888)
Django has migrations; why would this be harder with Django?
Re:When deployments are easy, code becomes simpler
by mrweasel on Wednesday September 06, 2023 @06:51AM
(#37403420)
The migrations is fairly tightly couple to the code. You can apply the migrations without deploying new code, if you extract the migrations, but now you have at least two branches in your version control, both of which are technically in production. You have the version that's actually running, and you have the version with the model changes and the migrations, from which you extracted the migrations and applied to the database.
I'd argue that because you're making the migrations from the model, it's also easier to do accidentally create migrations that are not independent of the code version.
Re:When deployments are easy, code becomes simpler
by robertlagrant on Wednesday September 06, 2023 @06:57AM
(#37403447)
Hm, but isn't that right? You make your change in code, which doesn't touch your models (except you're no longer using the column you'd like to deprecate), and deploy that; show it's working. Then you make another change to actually remove the column from the models and generate a migration. Then you deploy that version, which migrates the db and runs your new model code?
(You could in theory remove the column but not merge the migration if you wanted to show your code worked fully without that column in your ORM model before removing it from the DB as well?)
There shouldn't be any reason that you can't do it with Flyway, but I would be concerned about fighting Flyway a bit. I use Django a fair bit and I honestly don't see a good way to make this approach work for Django, not suggesting that you can't, but you would be fighting Django a fair bit, it's not really how it's designed to work.
If you don't have en ORM, then this is actually much much easier to do right. I'd design the initial schema, either by hand or using some pgAdmin, TOAD or whatever you database has. For there on everything is just hand written migrations.