-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trim whitespace of existing assignment and grouping titles
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
lms/migrations/versions/e5a9845d55d7_clean_grouping_and_assignment_titles.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,49 @@ | ||
"""Clean grouping and assignment titles. | ||
Revision ID: e5a9845d55d7 | ||
Revises: f8ff7e49cbbf | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
revision = "e5a9845d55d7" | ||
down_revision = "f8ff7e49cbbf" | ||
|
||
|
||
def upgrade() -> None: | ||
conn = op.get_bind() | ||
|
||
result = conn.execute( | ||
sa.text( | ||
""" | ||
UPDATE assignment SET title = TRIM(title) | ||
WHERE TRIM(title) != title; | ||
""" | ||
) | ||
) | ||
print(f"Assignment titles updated: {result.rowcount}") | ||
|
||
result = conn.execute( | ||
sa.text( | ||
""" | ||
UPDATE assignment SET title = null | ||
WHERE title = ''; | ||
""" | ||
) | ||
) | ||
print(f"Empty assignment titles: {result.rowcount}") | ||
|
||
result = conn.execute( | ||
sa.text( | ||
""" | ||
UPDATE grouping SET lms_name = TRIM(lms_name) | ||
WHERE TRIM(lms_name) != lms_name; | ||
""" | ||
) | ||
) | ||
print(f"Grouping titles updated: {result.rowcount}") | ||
|
||
|
||
def downgrade() -> None: | ||
pass |