-
Notifications
You must be signed in to change notification settings - Fork 77
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
Initialize the database automatically when starting mquery #421
Conversation
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.
This looks more complicated than I thought it would. I'll take a look at it and check if it can be simplified.
The reason behind it is that we don't have |
We should, otherwise how would previous migrations be applied? If previous documentation was giving incorrect instructions that bypass alembic it's unfortunate, but we don't have to accomodate such weird cases (database was not a part of any released version so it's not a critical problem). Sorry if that was not clear and you had to solve this problem unnecessarily. |
3fe6cd8
to
fa0510b
Compare
I still believe the previous version was severely overcomplicated. Pushed my suggestions/fixes. First thing is, chdir is extremely "dirty" thing to do, and in 99.9% of programs should never be called (it changes process' global state and may cause unpredictable problems). But even more importantly, this place is not guaranteed to exist. It only exists in the current docker environment, but the code should work outside of docker too (many deployments work this way). In this case, code is in a package, and we should just package alembic.ini and migrations. |
Your checklist for this pull request
What is the current behaviour?
Currently we needed to initilize database by hand:
python3 -m mquery.db
.What is the new behaviour?
Now the database initialization is automatic and it uses
alembic upgrade head
instad ofmquery.db
so it also applies migrations. Also if the database already exists it will stamp it and createalembic_version
for future migrations to be applied viaupgrade head
Test plan
For new instance: Create new instance and it will initilize database automatically.
For existing database: Remove (unnecessary for dev containers) web container and set it up again.
Then you can check if there is
alembic_version
in postgresql.Closing issues
fixes #402