fix(migration): handle deleted courses & users
This commit is contained in:
parent
e632ac06a3
commit
35621df03e
@ -653,7 +653,8 @@ customMigrations = Map.fromListWith (>>)
|
|||||||
let toAllocated :: [[PersistValue]] -> Maybe AllocationId
|
let toAllocated :: [[PersistValue]] -> Maybe AllocationId
|
||||||
toAllocated = either (const Nothing) Just . fromPersistValue <=< listToMaybe <=< listToMaybe
|
toAllocated = either (const Nothing) Just . fromPersistValue <=< listToMaybe <=< listToMaybe
|
||||||
allocated <- toAllocated <$> sourceToList [queryQQ|SELECT "allocation_course".allocation FROM "allocation_deregister" INNER JOIN "allocation_course" ON "allocation_course".course = "allocation_deregister".course WHERE "user" = #{transactionUser} AND "allocation_course"."course" = #{transactionCourse} LIMIT 1;|]
|
allocated <- toAllocated <$> sourceToList [queryQQ|SELECT "allocation_course".allocation FROM "allocation_deregister" INNER JOIN "allocation_course" ON "allocation_course".course = "allocation_deregister".course WHERE "user" = #{transactionUser} AND "allocation_course"."course" = #{transactionCourse} LIMIT 1;|]
|
||||||
[executeQQ|INSERT INTO "course_participant" ("course", "user", "registration", "state", "allocated") VALUES (#{transactionCourse}, #{transactionUser}, #{time}, #{CourseParticipantInactive False}, #{allocated}) ON CONFLICT DO NOTHING;|]
|
whenM (existsKey transactionCourse `and2M` existsKey transactionUser)
|
||||||
|
[executeQQ|INSERT INTO "course_participant" ("course", "user", "registration", "state", "allocated") VALUES (#{transactionCourse}, #{transactionUser}, #{time}, #{CourseParticipantInactive False}, #{allocated}) ON CONFLICT DO NOTHING;|]
|
||||||
ensureParticipant _ = return ()
|
ensureParticipant _ = return ()
|
||||||
runConduit $ getAuditLog .| C.mapM_ ensureParticipant
|
runConduit $ getAuditLog .| C.mapM_ ensureParticipant
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user