From e508277496f7aa4114ab9685166e91caab941226 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 6 May 2020 08:56:55 +0200 Subject: [PATCH] fix(migration): typos --- src/Model/Migration.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Migration.hs b/src/Model/Migration.hs index 51f41aec6..00feaee8c 100644 --- a/src/Model/Migration.hs +++ b/src/Model/Migration.hs @@ -647,12 +647,12 @@ customMigrations = Map.fromListWith (>>) ALTER TABLE "course_participant" ADD COLUMN "state" text NOT NULL DEFAULT 'active'; ALTER TABLE "course_participant" ALTER COLUMN "state" DROP DEFAULT; |] - let getAuditLog = rawQuery [st|SELECT "info", "time" FROM "transaction_log";|] [] + let getAuditLog = rawQuery [st|SELECT DISTINCT ON ("info") "info", max("time") FROM "transaction_log" GROUP BY "info" ORDER BY "info";|] [] ensureParticipant :: [PersistValue] -> ReaderT SqlBackend m () ensureParticipant [fmap Aeson.fromJSON . fromPersistValue -> Right (Aeson.Success TransactionCourseParticipantEdit{..}), fromPersistValue -> Right (time :: UTCTime)] = do 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 "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;|] ensureParticipant _ = return () runConduit $ getAuditLog .| C.mapM_ ensureParticipant