From 17a3541fe29db3e2101746745b36ecf1d5cd5c23 Mon Sep 17 00:00:00 2001 From: Steffen Date: Fri, 8 Mar 2024 13:26:34 +0100 Subject: [PATCH] chore(db): ass comments on upsertManyWhere usage --- test/Database/Fill.hs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/test/Database/Fill.hs b/test/Database/Fill.hs index c1c657912..af8961dba 100644 --- a/test/Database/Fill.hs +++ b/test/Database/Fill.hs @@ -696,9 +696,22 @@ fillDb = do ++ take 444 [ UserSupervisor fhamann uid True | Entity uid _ <- matUsers, uid /= jost] ++ take 123 [ UserSupervisor gkleen uid True | Entity uid _ <- drop 369 matUsers ] ++ take 11 [ UserSupervisor jost uid False | Entity uid _ <- drop 501 matUsers ] - upsertManyWhere supvs [] [] [] - -- upsertManyWhere supvs [] [] [] -- NOTE: multiple calls like this are ok - -- insertMany_ supvs -- NOTE: multiple calls like this throw an error! + upsertManyWhere supvs [] [] [] + -- insertMany_ supvs -- NOTE: multiple calls like this throw a runtime error! + -- upsertManyWhere supvs [] [] [] -- NOTE: multiple calls like this are ok + -- upsertManyWhere (supvs ++ take 5 (drop 12 [ UserSupervisor jost uid False | Entity uid _ <- drop 501 matUsers ])) -- no duplicates within first argument allowed! (runtime error: ON CONFLICT DO UPDATE command cannot affect row a second time) + -- [copyField UserSupervisorRerouteNotifications] [UserSupervisorRerouteNotifications =. True] [UserSupervisorSupervisor ==. jost, UserSupervisorUser <-. [uid | Entity uid _ <- take 3 $ drop 504 matUsers ]] -- does not work! + -- let changeSome usr@(UserSupervisor s u _) + -- | s == jost, u `elem` take 14 [ uid | Entity uid _ <- drop 501 matUsers ] = UserSupervisor s u True + -- | otherwise = usr + -- upsertManyWhere (changeSome <$> (supvs ++ take 5 (drop 12 [ UserSupervisor jost uid False | Entity uid _ <- drop 501 matUsers ]))) -- no duplicates within first argument allowed! (runtime error: ON CONFLICT DO UPDATE command cannot affect row a second time) + -- [copyField UserSupervisorRerouteNotifications] [] [UserSupervisorSupervisor ==. jost, UserSupervisorUser <-. [uid | Entity uid _ <- take 3 $ drop 504 matUsers ]] -- probably does the same as the above + -- OBSERVATIONS: + -- - use the 2. argument with `copyField` to overwrite an existing field with the new record value provided in the 1. argument in case of an update + -- - use the 3. argument to update a field indepently from the provided records or for computations involving previous values, eg. +=. + -- - use the 4. argument to filter both the application of the 2. and 3. argument + + ifi <- insert' $ School "Institut für Informatik" "IfI" (Just $ 14 * nominalDay) (Just $ 10 * nominalDay) True (ExamModeDNF predDNFFalse) (ExamCloseOnFinished True) SchoolAuthorshipStatementModeOptional (Just ifiAuthorshipStatement) True SchoolAuthorshipStatementModeRequired (Just ifiAuthorshipStatement) False mi <- insert' $ School "Institut für Mathematik" "MI" Nothing Nothing False (ExamModeDNF predDNFFalse) (ExamCloseOnFinished False) SchoolAuthorshipStatementModeNone Nothing True SchoolAuthorshipStatementModeOptional Nothing True