diff --git a/src/Model/Migration.hs b/src/Model/Migration.hs index 00feaee8c..e041bfd7b 100644 --- a/src/Model/Migration.hs +++ b/src/Model/Migration.hs @@ -653,7 +653,8 @@ customMigrations = Map.fromListWith (>>) let toAllocated :: [[PersistValue]] -> Maybe AllocationId 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;|] - [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 () runConduit $ getAuditLog .| C.mapM_ ensureParticipant )