Skip to content

Commit

Permalink
Backfill LMSUSerApplication instance
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Aug 29, 2024
1 parent 00a8b2d commit 1c234f0
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Backfill lms_user_application_instance."""

import sqlalchemy as sa
from alembic import op

revision = "e13fb37c96e5"
down_revision = "f61cb94edfc8"


def upgrade() -> None:
conn = op.get_bind()
conn.execute(
sa.text(
"""
WITH backfill as (
SELECT
"user".created,
"user".updated,
lms_user.id lms_user_id,
"user".application_instance_id
FROM "user"
JOIN lms_user on lms_user.h_userid = "user".h_userid
)
INSERT INTO lms_user_application_instance (
created,
updated,
lms_user_id,
application_instance_id
)
SELECT
created,
updated,
lms_user_id,
application_instance_id
FROM backfill
ON CONFLICT (lms_user_id, application_instance_id) DO NOTHING
"""
)
)


def downgrade() -> None:
pass

0 comments on commit 1c234f0

Please sign in to comment.