-
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.
Backfill LMSCourseApplication instance
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
lms/migrations/versions/9e79650bed37_backfill_lms_course_application_instance.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,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 |