-
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.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
lms/migrations/versions/ba295703738b_backfill_lmsgroupset.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,39 @@ | ||
"""Backfill LMSGroupSet.""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
revision = "ba295703738b" | ||
down_revision = "4b813a44a6c9" | ||
|
||
|
||
def upgrade() -> None: | ||
conn = op.get_bind() | ||
conn.execute( | ||
sa.text( | ||
""" | ||
WITH backfill as ( | ||
SELECT lms_course.id lms_course_id, course_group_sets.id group_set_id, course_group_sets.name group_set_name | ||
FROM grouping | ||
JOIN lms_course ON grouping.authority_provided_id = lms_course.h_authority_provided_id | ||
CROSS JOIN LATERAL jsonb_to_recordset(grouping.extra->'group_sets') as course_group_sets(id Text, name Text) | ||
) | ||
INSERT INTO lms_group_set ( | ||
lms_course_id, | ||
lms_id, | ||
name | ||
) | ||
SELECT | ||
lms_course_id, | ||
group_set_id, | ||
group_set_name | ||
FROM backfill | ||
-- We are already inserting rows in the python code, leave those alone | ||
ON CONFLICT (lms_course_id, lms_id) DO NOTHING | ||
""" | ||
) | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
pass |