From 03871a3e7cd8c59d92cdd848d66ddb4677659a0b Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Fri, 23 Aug 2024 11:57:24 +0200 Subject: [PATCH] Backfill LMSCourseApplication instance --- ...ackfill_lms_course_application_instance.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lms/migrations/versions/9e79650bed37_backfill_lms_course_application_instance.py diff --git a/lms/migrations/versions/9e79650bed37_backfill_lms_course_application_instance.py b/lms/migrations/versions/9e79650bed37_backfill_lms_course_application_instance.py new file mode 100644 index 0000000000..ebdd6b0da2 --- /dev/null +++ b/lms/migrations/versions/9e79650bed37_backfill_lms_course_application_instance.py @@ -0,0 +1,43 @@ +"""LMSCourseApplicationInstance backfill.""" + +import sqlalchemy as sa +from alembic import op + +revision = "9e79650bed37" +down_revision = "e13fb37c96e5" + + +def upgrade() -> None: + conn = op.get_bind() + conn.execute( + sa.text( + """ + WITH backfill as ( + SELECT + "grouping".created, + "grouping".updated, + lms_course.id lms_course_id, + "grouping".application_instance_id + FROM "grouping" + JOIN lms_course on lms_course.h_authority_provided_id = "grouping".authority_provided_id + ) + INSERT INTO lms_course_application_instance ( + created, + updated, + lms_course_id, + application_instance_id + ) + SELECT + created, + updated, + lms_course_id, + application_instance_id + FROM backfill + ON CONFLICT (lms_course_id, application_instance_id) DO NOTHING + """ + ) + ) + + +def downgrade() -> None: + pass