-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use aerich
for database migrations
#1110
Conversation
1d47481
to
0ec6868
Compare
- Write Changelog and a first draft for the docs - Abort migration commands if it's not initialized - Refactor the initialization to `DipDup._initialize_migrations` - Schema is approved automatically after upgrade and downgrade - `wipe_schema` also removes the `migration_dir`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thanks for your contribution! It's a great code with many smart solutions; I like every piece of it! My only concern is making this integration optional in every way: dependencies, imports, files in the project package.
- aerich is now an optional dependency under the optional migrations group - migrations folder is hardcoded in the DipDupPackage class - migrations commands and folder will only be added if aerich is installed
0505890
to
aa179fc
Compare
Do you guys prefer |
@bigherc18 We squash every merge request, so it's up to you what's inside. |
Some concerns and limitations I have:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your last comment shows such a great amount of testing done! 🥰 I think, there's nothing critical. Yes, running commands in random order on multiple databases sometimes confuse aerich, but all real cases works perfectly.
I have just a few nitpicks. Then make sure that make all docs
command passes, add yourself to the thanks.md
file, and let's merge it!
Thank you for your feedback but I just want to make sure I explained my concerns clear enough for you
TLDR; if a user uses multiple databases at the same time, migrations is not supported I see dipdup makes it easy for users to swap databases by just combining different config files with multiple I think this worth at least a note in the docs
Here's a little video demonstrating the issue: |
This PR is about using
aerich
to add support for database migrationsHere's a demo: https://asciinema.org/a/Sw7OwQZKmWyznV3xgohjd59OT
I added a new config called
migrations_dir
to specify where migration files should be storedA a set of commands have been added to manage database migrations:
dipdup schema history
to show the migration historydipdup schema heads
to show the show the current available headsdipdup schema migrate
to create a new migration changes filedipdup schema upgrade
to upgrade the database to the latest or a specified versiondipdup schema downgrade
to downgrade the database to a previous versionTheses commands invoke
aerich
's commands under the hoodThe migrations directory should be initialized before using any of these commands, either with
dipdup schema init
or by running the indexer withdipdup run
.Note that
aerich
commands can't be used directly, as it expects the config to be stored inpyproject.toml