Skip to content

Commit

Permalink
Backfill migration for LMSGroupSet
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Nov 5, 2024
1 parent 6927cf9 commit e519f1a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lms/migrations/versions/ba295703738b_backfill_lmsgroupset.py
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

0 comments on commit e519f1a

Please sign in to comment.