-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: alembic revision for auto release
- Loading branch information
1 parent
de56217
commit 06a565c
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
grader_service/migrate/versions/e52c1a6c91fb_auto_release.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""auto release | ||
Revision ID: e52c1a6c91fb | ||
Revises: a0718dae969d | ||
Create Date: 2024-10-09 13:21:54.080731 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'e52c1a6c91fb' | ||
down_revision = 'a0718dae969d' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
new_enum = sa.Enum( | ||
'created', 'pushed', 'released', 'fetching', 'fetched', 'complete', 'release_scheduled', | ||
name='assignment_status' | ||
) | ||
|
||
|
||
def upgrade(): | ||
# Sqlite doesn't support ALTER table, so make backup of status column, drop original status column and make a new one wit new enum values | ||
op.add_column('assignment', sa.Column('status_backup', sa.String(), nullable=True)) | ||
op.execute("UPDATE assignment SET status_backup = status") | ||
op.drop_column('assignment', 'status') | ||
new_enum.create(op.get_bind(), checkfirst=True) | ||
op.add_column('assignment', sa.Column('status', new_enum, nullable=True)) | ||
op.execute("UPDATE assignment SET status = status_backup") | ||
op.drop_column('assignment', 'status_backup') | ||
|
||
|
||
def downgrade(): | ||
# Remove 'release_scheduled' from assignment status options | ||
op.add_column('assignment', sa.Column('status_backup', sa.String(), nullable=True)) | ||
|
||
op.execute(" UPDATE assignment SET status_backup = status") | ||
|
||
op.drop_column('assignment', 'status') | ||
old_enum = sa.Enum( | ||
'created', 'pushed', 'released', 'fetching', 'fetched', 'complete', | ||
name='assignment_status' | ||
) | ||
old_enum.create(op.get_bind(), checkfirst=True) | ||
op.add_column('assignment', sa.Column('status', old_enum, nullable=True)) | ||
|
||
# If assignment status was 'release_scheduled' after downgrade it should be 'created' as the assignment is still not 'released' | ||
op.execute(""" | ||
UPDATE assignment | ||
SET status = CASE | ||
WHEN status_backup = 'release_scheduled' THEN 'created' | ||
ELSE status_backup | ||
END; | ||
""") | ||
|
||
op.drop_column('assignment', 'status_backup') | ||
new_enum.drop(op.get_bind(), checkfirst=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters