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

Trim whitespace of existing assignment and grouping titles #6477

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Member Author

Choose a reason for hiding this comment

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

sa.text(
"""
UPDATE assignment SET title = TRIM(title)
WHERE TRIM(title) != title;
Copy link
Contributor

Choose a reason for hiding this comment

The 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 UPDATE assignment SET title = TRIM(title)?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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(
Copy link
Member Author

Choose a reason for hiding this comment

The 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(
Copy link
Member Author

Choose a reason for hiding this comment

The 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
Loading