-
Notifications
You must be signed in to change notification settings - Fork 14
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
Trim whitespace of existing assignment and grouping titles #6477
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this really make a difference? Couldn't we just get away with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, while the where makes the query slower it should lock less rows which should be safer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point. |
||
""" | ||
) | ||
) | ||
print(f"Assignment titles updated: {result.rowcount}") | ||
|
||
result = conn.execute( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
sa.text( | ||
""" | ||
UPDATE assignment SET title = null | ||
WHERE title = ''; | ||
""" | ||
) | ||
) | ||
print(f"Empty assignment titles: {result.rowcount}") | ||
|
||
result = conn.execute( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 |
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.
7700 rows: https://metabase.hypothes.is/question#eyJkYXRhc2V0X3F1ZXJ5Ijp7InR5cGUiOiJuYXRpdmUiLCJuYXRpdmUiOnsicXVlcnkiOiJzZWxlY3QgY291bnQoKikgZnJvbSBhc3NpZ25tZW50IHdoZXJlIHRyaW0odGl0bGUpICE9IHRpdGxlIFxuIiwidGVtcGxhdGUtdGFncyI6e319LCJkYXRhYmFzZSI6N30sImRpc3BsYXkiOiJ0YWJsZSIsInBhcmFtZXRlcnMiOltdLCJ2aXN1YWxpemF0aW9uX3NldHRpbmdzIjp7fX0=