From 35621df03ece390d9513871c9def990828a51ecf Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 6 May 2020 12:52:53 +0200 Subject: [PATCH] fix(migration): handle deleted courses & users --- src/Model/Migration.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 )