From 590e3928a5a5765fadc845c0f31eed2ca5d2e35f Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sat, 29 Jun 2019 17:18:48 +0000 Subject: [PATCH] Vervis.Migration: Replace fromJust in migration #109 with informative error --- src/Vervis/Migration.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index b801549..2b6a958 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -44,7 +44,7 @@ import Database.Persist.Migration import Database.Persist.Schema (SchemaT, Migration) import Database.Persist.Schema.Types hiding (Entity) import Database.Persist.Schema.PostgreSQL (schemaBackend) -import Database.Persist.Sql (SqlBackend, toSqlKey) +import Database.Persist.Sql (SqlBackend, toSqlKey, fromSqlKey) import Text.Blaze.Html (toHtml, preEscapedToHtml) import Text.Blaze.Html.Renderer.Text --import Text.Email.QuasiQuotation (email @@ -646,17 +646,24 @@ changes hLocal ctx = ) "InboxItem neither remote nor local" "InboxItem both remote and local" - let getValByJust = fmap fromJust . getValBy + let getValByJust mkuniq id_ desc = do + mval <- getValBy $ mkuniq id_ + case mval of + Nothing -> + error $ + desc ++ show (fromSqlKey id_) ++ + " isn't the Create of any Message" + Just val -> return val for_ (nub activities) $ \ activity -> do mid <- case activity of Left obid -> localMessage2019FillRest <$> getValByJust - (UniqueLocalMessageCreate2019Fill obid) + UniqueLocalMessageCreate2019Fill obid "obiid" Right ractid -> remoteMessage2019FillRest <$> getValByJust - (UniqueRemoteMessageCreate2019Fill ractid) + UniqueRemoteMessageCreate2019Fill ractid "ractid" did <- message2019FillRoot <$> getJust mid mt <- getValBy $ UniqueTicketDiscussion2019Fill did for_ mt $ \ t -> do