From 322d09658e9d98bb1042f48911ce54ff310c9f94 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 9 Jun 2019 18:41:37 +0000 Subject: [PATCH] (Hopefully correctly) fill project inboxes with ticket comment Create Notes --- config/models | 1 + src/Vervis/Migration.hs | 40 +++++++++++++++++++++++++++++++++++ src/Vervis/Migration/Model.hs | 12 +++++++++++ 3 files changed, 53 insertions(+) diff --git a/config/models b/config/models index d5ee5c6..5e95012 100644 --- a/config/models +++ b/config/models @@ -363,6 +363,7 @@ RemoteMessage UniqueRemoteMessageIdent instance ident UniqueRemoteMessage rest + UniqueRemoteMessageCreate create RepoCollab repo RepoId diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index ac28280..26cc662 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -31,12 +31,14 @@ import Data.ByteString (ByteString) import Data.Default.Class import Data.Default.Instances.ByteString () import Data.Foldable (traverse_, for_) +import Data.List (nub) import Data.Maybe import Data.Proxy import Data.Text (Text) import Data.Text.Encoding (encodeUtf8) import Data.Time.Calendar (Day (..)) import Data.Time.Clock +import Data.Traversable import Database.Persist import Database.Persist.BackendDataType (backendDataType, PersistDefault (..)) import Database.Persist.Migration @@ -61,6 +63,7 @@ import Web.ActivityPub import Yesod.FedURI import Yesod.Hashids +import Data.Either.Local import Database.Persist.Local import Vervis.Model.Ident @@ -609,6 +612,43 @@ changes hLocal ctx = "Inbox" -- 107 , addUnique "Project" $ Unique "UniqueProjectInbox" ["inbox"] + -- 108 + , addUnique "RemoteMessage" $ Unique "UniqueRemoteMessageCreate" ["create"] + -- 109 + , unchecked $ lift $ do + ibiids <- selectKeysList ([] :: [Filter InboxItem2019Fill]) [] + activities <- for ibiids $ \ ibiid -> + requireEitherAlt + (fmap inboxItemLocal2019FillActivity <$> + getValBy (UniqueInboxItemLocalItem2019Fill ibiid) + ) + (fmap inboxItemRemote2019FillActivity <$> + getValBy (UniqueInboxItemRemoteItem2019Fill ibiid) + ) + "InboxItem neither remote nor local" + "InboxItem both remote and local" + let getValByJust = fmap fromJust . getValBy + for_ (nub activities) $ \ activity -> do + mid <- case activity of + Left obid -> + localMessage2019FillRest <$> + getValByJust + (UniqueLocalMessageCreate2019Fill obid) + Right ractid -> + remoteMessage2019FillRest <$> + getValByJust + (UniqueRemoteMessageCreate2019Fill ractid) + did <- message2019FillRoot <$> getJust mid + mt <- getValBy $ UniqueTicketDiscussion2019Fill did + for_ mt $ \ t -> do + ibid <- + project2019FillInbox <$> getJust (ticket2019FillProject t) + ibiid <- insert $ InboxItem2019Fill False + case activity of + Left obid -> + insert_ $ InboxItemLocal2019Fill ibid obid ibiid + Right ractid -> + insert_ $ InboxItemRemote2019Fill ibid ractid ibiid ] migrateDB diff --git a/src/Vervis/Migration/Model.hs b/src/Vervis/Migration/Model.hs index f7a4174..4a89933 100644 --- a/src/Vervis/Migration/Model.hs +++ b/src/Vervis/Migration/Model.hs @@ -70,6 +70,15 @@ module Vervis.Migration.Model , InboxItemRemote20190607 , Project20190609 , Inbox20190609Generic (..) + , InboxItem2019FillGeneric (..) + , InboxItem2019Fill + , InboxItemLocal2019FillGeneric (..) + , InboxItemRemote2019FillGeneric (..) + , Project2019FillGeneric (..) + , Ticket2019FillGeneric (..) + , Message2019FillGeneric (..) + , LocalMessage2019FillGeneric (..) + , RemoteMessage2019FillGeneric (..) ) where @@ -171,3 +180,6 @@ makeEntitiesMigration "20190607" makeEntitiesMigration "20190609" $(modelFile "migrations/2019_06_09.model") + +makeEntitiesMigration "2019Fill" + $(modelFile "migrations/2019_06_09_fill.model")