-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from eoyilmaz/74-remove-projectis_active-attr…
…ibute [#74] Removed `Project.active` attribute and the related column. The …
- Loading branch information
Showing
6 changed files
with
92 additions
and
27 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
alembic/versions/644f5251fc0d_remove_project_active_attribute.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,46 @@ | ||
"""Remove Project.active attribute | ||
Revision ID: 644f5251fc0d | ||
Revises: 5078390e5527 | ||
Create Date: 2024-11-18 12:47:09.673241 | ||
""" | ||
|
||
from alembic import op | ||
|
||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "644f5251fc0d" | ||
down_revision = "5078390e5527" | ||
|
||
|
||
def upgrade(): | ||
"""Upgrade the tables.""" | ||
# just remove the "active" column | ||
with op.batch_alter_table("Projects", schema=None) as batch_op: | ||
batch_op.drop_column("active") | ||
|
||
|
||
def downgrade(): | ||
"""Downgrade the tables.""" | ||
with op.batch_alter_table("Projects", schema=None) as batch_op: | ||
batch_op.add_column(sa.Column("active", sa.Boolean(), nullable=True)) | ||
|
||
# restore the value by checking the status | ||
op.execute( | ||
"""UPDATE "Projects" SET active = ( | ||
SELECT | ||
( | ||
CASE WHEN "Projects".status_id = ( | ||
SELECT | ||
"Statuses".id | ||
FROM "Statuses" | ||
WHERE "Statuses".code = 'WIP' | ||
) | ||
THEN true ELSE false END | ||
) as active | ||
FROM "Projects" | ||
) | ||
""" | ||
) |
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
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
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
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
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