(Hopefully correctly) fill project inboxes with ticket comment Create Notes

This commit is contained in:
fr33domlover 2019-06-09 18:41:37 +00:00
parent bad1844cfc
commit 322d09658e
3 changed files with 53 additions and 0 deletions

View file

@ -363,6 +363,7 @@ RemoteMessage
UniqueRemoteMessageIdent instance ident UniqueRemoteMessageIdent instance ident
UniqueRemoteMessage rest UniqueRemoteMessage rest
UniqueRemoteMessageCreate create
RepoCollab RepoCollab
repo RepoId repo RepoId

View file

@ -31,12 +31,14 @@ import Data.ByteString (ByteString)
import Data.Default.Class import Data.Default.Class
import Data.Default.Instances.ByteString () import Data.Default.Instances.ByteString ()
import Data.Foldable (traverse_, for_) import Data.Foldable (traverse_, for_)
import Data.List (nub)
import Data.Maybe import Data.Maybe
import Data.Proxy import Data.Proxy
import Data.Text (Text) import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8) import Data.Text.Encoding (encodeUtf8)
import Data.Time.Calendar (Day (..)) import Data.Time.Calendar (Day (..))
import Data.Time.Clock import Data.Time.Clock
import Data.Traversable
import Database.Persist import Database.Persist
import Database.Persist.BackendDataType (backendDataType, PersistDefault (..)) import Database.Persist.BackendDataType (backendDataType, PersistDefault (..))
import Database.Persist.Migration import Database.Persist.Migration
@ -61,6 +63,7 @@ import Web.ActivityPub
import Yesod.FedURI import Yesod.FedURI
import Yesod.Hashids import Yesod.Hashids
import Data.Either.Local
import Database.Persist.Local import Database.Persist.Local
import Vervis.Model.Ident import Vervis.Model.Ident
@ -609,6 +612,43 @@ changes hLocal ctx =
"Inbox" "Inbox"
-- 107 -- 107
, addUnique "Project" $ Unique "UniqueProjectInbox" ["inbox"] , 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 migrateDB

View file

@ -70,6 +70,15 @@ module Vervis.Migration.Model
, InboxItemRemote20190607 , InboxItemRemote20190607
, Project20190609 , Project20190609
, Inbox20190609Generic (..) , Inbox20190609Generic (..)
, InboxItem2019FillGeneric (..)
, InboxItem2019Fill
, InboxItemLocal2019FillGeneric (..)
, InboxItemRemote2019FillGeneric (..)
, Project2019FillGeneric (..)
, Ticket2019FillGeneric (..)
, Message2019FillGeneric (..)
, LocalMessage2019FillGeneric (..)
, RemoteMessage2019FillGeneric (..)
) )
where where
@ -171,3 +180,6 @@ makeEntitiesMigration "20190607"
makeEntitiesMigration "20190609" makeEntitiesMigration "20190609"
$(modelFile "migrations/2019_06_09.model") $(modelFile "migrations/2019_06_09.model")
makeEntitiesMigration "2019Fill"
$(modelFile "migrations/2019_06_09_fill.model")