-
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 LMSUserAssignmentMembership based on AssignmentMembership rows
Now that the python code creates LMSUserAssignmentMembership rows on each assignment backfill the existing data in one migration.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
lms/migrations/versions/a9e5a33e96b7_backfill_lmsuserassignmentmembership.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,50 @@ | ||
"""Backfill LMSUserAssignmentMembership.""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
revision = "a9e5a33e96b7" | ||
down_revision = "712c4c9a4e2e" | ||
|
||
|
||
def upgrade() -> None: | ||
conn = op.get_bind() | ||
conn.execute( | ||
sa.text( | ||
""" | ||
WITH backfill as ( | ||
SELECT | ||
assignment_membership.created, | ||
assignment_membership.updated, | ||
assignment_membership.assignment_id, | ||
lms_user.id as lms_user_id, | ||
lti_role_id | ||
FROM assignment_membership | ||
JOIN "user" on assignment_membership.user_id = "user".id | ||
JOIN "lms_user" on "user".h_userid = "lms_user".h_userid | ||
) | ||
INSERT INTO lms_user_assignment_membership ( | ||
created, | ||
updated, | ||
assignment_id, | ||
lms_user_id, | ||
lti_role_id | ||
) | ||
SELECT | ||
created, | ||
updated, | ||
assignment_id, | ||
lms_user_id, | ||
lti_role_id | ||
FROM backfill | ||
-- We are already inserting rows in the table on the python code, leave those alone | ||
ON CONFLICT ON CONSTRAINT uq__lms_user_assignment_membership__assignment_id DO NOTHING | ||
""" | ||
) | ||
) | ||
|
||
pass | ||
|
||
|
||
def downgrade() -> None: | ||
pass |