Offline migrations creating #441
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context:
Right now aerich creates migrations based on diff between latest
content
in aerich table in db.This creates several problems, for example:
#309
#270
Because of such a way of handling it - it creates problems with setting up existing project on new env/new db, as new user does not have any knowledge about models state at given moment of time, and in best case scenario - you can run upgrade and it will save current state of models to all aerich table rows, which is wrong by itself
Also it creates problems with sequentially creating several migrations without upgrading database in between.
Overall - this methodic of storing model state is problematic and inconvenient
This PR aims to tackle those issues
Description:
New approach saves current models state as encoded string within file itself, enabling offline migration management, without comparing with version in database. That solves problems for setting up application in new env and improves experience for people who develop their apps without available connection to db, which can be common for bigger projects
It also provides method fix-migrations to update migrations to new format, although that requires existing db with migrations applied to work properly
Known issues
Right now - this approach is not fully "offline" as it still need to connection to db for two things:
I believe both of this issues are solvable
I'll try to work on both of this solutions in upcoming days
Alternatives
I think storing information about models state through files is necessary one way or another. Better approach would be storing only diff between models, but if we go down this route - it's even better to calculate models state on the go, by parsing migration changes themself.
But such approach leads us into rabbit hole of making full fledged django like migration system, which is neat, but far bigger than all existing aerich code, so I don't think it's feasible for me in the moment