From 8623364c7b95a6a55bb1ef3149319a2c8302fcba Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Mon, 29 Jul 2024 10:21:40 +0200 Subject: [PATCH] Trim whitespace of existing assignment and grouping titles --- ...d7_clean_grouping_and_assignment_titles.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lms/migrations/versions/e5a9845d55d7_clean_grouping_and_assignment_titles.py diff --git a/lms/migrations/versions/e5a9845d55d7_clean_grouping_and_assignment_titles.py b/lms/migrations/versions/e5a9845d55d7_clean_grouping_and_assignment_titles.py new file mode 100644 index 0000000000..aaa44b1300 --- /dev/null +++ b/lms/migrations/versions/e5a9845d55d7_clean_grouping_and_assignment_titles.py @@ -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