Vervis.Migration: Replace fromJust in migration #109 with informative error

This commit is contained in:
fr33domlover 2019-06-29 17:18:48 +00:00
parent 6d72d676e7
commit 590e3928a5

View file

@ -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