-
Notifications
You must be signed in to change notification settings - Fork 76
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
Create proper enums for job statuses #412
base: master
Are you sure you want to change the base?
Conversation
|
||
def upgrade() -> None: | ||
op.create_table( |
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.
Why this change? We should not change older migrations in any case. (Please also don't reformat them, to keep unnecessary git changes to minimum)
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.
Ok. I understand. I did this because the alembic upgrade head command in an existing environment causes errors that the table exists. So I check beforehand if the table exists.
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"jobagent", |
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.
similarly, please don't change and reformat this file
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.
Ok
docker compose exec web python3 -m mquery.db | ||
docker compose exec web python3 -m alembic upgrade head |
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.
Not sure about this. We want to reduce the number of additional commands to zero (#402), not add more of them.
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.
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.
Not sure about this. We want to reduce the number of additional commands to zero (#402), not add more of them.
All because of alembic, which does not automatically recognize the modification from varchar to enum. I am able to create an enum type in postgres from the model level, but alembic does not replace it (it still remains VARCHAR) - that's why my manual modifications in migration files.
I found a library https://pypi.org/project/alembic-postgresql-enum/, quite new, I have to test it, but the question is whether to enter something like that at all. Or maybe look for solutions in sqlalchemy dialects for postgresql
|
||
def upgrade() -> None: | ||
op.execute( | ||
"CREATE TYPE jobstatus AS ENUM ('done', 'new', 'cancelled', 'removed', 'processing');" |
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.
You don't need to know every possible type for this migration. Just change every value out of scope to cancelled
and then convert to enum.
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.
(But good point that we need to handle this correctly)
By the way, I've created an issue for removing the "removed" status. #414 It may be a good time to implement it (for you it's just a few lines of code now, but it'll require another migration if done separately). If that's OK, please also remove this status from code at this time. |
Your checklist for this pull request
What is the current behaviour?
Status column in Job model exists as a string
What is the new behaviour?
Status column in Job model is as a JobStatus enum.