Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

michalkrzem
Copy link
Collaborator

@michalkrzem michalkrzem commented Oct 1, 2024

Your checklist for this pull request

  • I've read the contributing guideline.
  • I've tested my changes by building and running mquery, and testing changed functionality (if applicable)
  • I've added automated tests for my change (if applicable, optional)
  • I've updated documentation to reflect my change (if applicable)

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.

@michalkrzem michalkrzem linked an issue Oct 1, 2024 that may be closed by this pull request
@msm-cert msm-cert changed the title 370 create proper enums for job statuses Create proper enums for job statuses Oct 2, 2024
@michalkrzem michalkrzem marked this pull request as ready for review October 2, 2024 14:11

def upgrade() -> None:
op.create_table(
Copy link
Member

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)

Copy link
Collaborator Author

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",
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Comment on lines 23 to +24
docker compose exec web python3 -m mquery.db
docker compose exec web python3 -m alembic upgrade head
Copy link
Member

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.

Copy link
Member

@msm-cert msm-cert Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't want to fix this in this PR and want to work separately in #402, it's OK to leave it as it is now (i.e. don't change the documentation in this PR. It works for fresh installations, just doesn't run migrations automatically).

If you want, I'll add some hints to #402 how to approach it

Copy link
Collaborator Author

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');"
Copy link
Member

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 cancelledand then convert to enum.

Copy link
Member

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)

@msm-cert
Copy link
Member

msm-cert commented Oct 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create proper enums for Job statuses
2 participants