From 5b570394474444534788deb1d1d127939e50175a Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Fri, 7 Feb 2020 19:42:02 +0000 Subject: [PATCH] DB: Point from TicketAuthorRemote to TicketProjectLocal --- config/models | 2 + migrations/2020_02_08_tar_point_to_tpl.model | 73 ++++++++++++++++++++ src/Vervis/Federation/Ticket.hs | 3 +- src/Vervis/Migration.hs | 54 +++++++++++++++ src/Vervis/Migration/Model.hs | 14 ++++ 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 migrations/2020_02_08_tar_point_to_tpl.model diff --git a/config/models b/config/models index a7bdc3a..39315d9 100644 --- a/config/models +++ b/config/models @@ -382,10 +382,12 @@ TicketAuthorLocal TicketAuthorRemote ticket TicketId + ticketNew TicketProjectLocalId author RemoteActorId offer RemoteActivityId UniqueTicketAuthorRemote ticket + UniqueTicketAuthorRemoteNew ticketNew UniqueTicketAuthorRemoteOffer offer TicketDependency diff --git a/migrations/2020_02_08_tar_point_to_tpl.model b/migrations/2020_02_08_tar_point_to_tpl.model new file mode 100644 index 0000000..5504ab6 --- /dev/null +++ b/migrations/2020_02_08_tar_point_to_tpl.model @@ -0,0 +1,73 @@ +Sharer + ident ShrIdent + name Text Maybe + created UTCTime + + UniqueSharer ident + +Outbox + +OutboxItem + outbox OutboxId + activity PersistJSONObject + published UTCTime + +Inbox + +FollowerSet + +Project + ident PrjIdent + sharer SharerId + name Text Maybe + desc Text Maybe + workflow WorkflowId + nextTicket Int + wiki Int64 Maybe + collabUser Int64 Maybe + collabAnon Int64 Maybe + inbox InboxId + outbox OutboxId + followers FollowerSetId + + UniqueProject ident sharer + UniqueProjectInbox inbox + UniqueProjectOutbox outbox + UniqueProjectFollowers followers + +Workflow + sharer SharerId + ident WflIdent + name Text Maybe + desc Text Maybe + scope WorkflowScope + + UniqueWorkflow sharer ident + +Ticket + number Int Maybe + created UTCTime + title Text -- HTML + source Text -- Pandoc Markdown + description Text -- HTML + assignee Int64 Maybe + status Text + closed UTCTime + closer Int64 Maybe + +TicketProjectLocal + ticket TicketId + project ProjectId + accept OutboxItemId + + UniqueTicketProjectLocal ticket + UniqueTicketProjectLocalAccept accept + +TicketAuthorRemote + ticket TicketId + ticketNew TicketProjectLocalId + author Int64 + offer Int64 + + UniqueTicketAuthorRemote ticket + UniqueTicketAuthorRemoteOffer offer diff --git a/src/Vervis/Federation/Ticket.hs b/src/Vervis/Federation/Ticket.hs index 13901c0..5139314 100644 --- a/src/Vervis/Federation/Ticket.hs +++ b/src/Vervis/Federation/Ticket.hs @@ -278,13 +278,14 @@ projectOfferTicketF , localTicketDiscuss = did , localTicketFollowers = fsid } - insert_ TicketProjectLocal + tplid <- insert TicketProjectLocal { ticketProjectLocalTicket = tid , ticketProjectLocalProject = jid , ticketProjectLocalAccept = obiidAccept } insert_ TicketAuthorRemote { ticketAuthorRemoteTicket = tid + , ticketAuthorRemoteTicketNew = tplid , ticketAuthorRemoteAuthor = raidAuthor , ticketAuthorRemoteOffer = ractid } diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 7702fd8..6b4040d 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -1342,6 +1342,60 @@ changes hLocal ctx = , removeUnique "Ticket" "UniqueTicketAccept" -- 204 , removeField "Ticket" "accept" + -- 205 + , addFieldRefRequired'' + "TicketAuthorRemote" + (do tid <- insert $ Ticket205 Nothing defaultTime "" "" "" Nothing "TSNew" defaultTime Nothing + jid <- do + let temp = "$$temp$$" + sid <- insert $ Sharer205 (text2shr temp) Nothing defaultTime + wid <- insert $ Workflow205 sid (text2wfl temp) Nothing Nothing WSSharer + ibid <- insert Inbox205 + obid <- insert Outbox205 + fsid <- insert FollowerSet205 + insert $ Project205 (text2prj temp) sid Nothing Nothing wid 1 Nothing Nothing Nothing ibid obid fsid + obiid <- do + obid <- insert Outbox205 + let h = Authority "x.y" Nothing :: Host + doc = Doc h emptyActivity + insert $ OutboxItem205 obid (persistJSONObjectFromDoc doc) defaultTime + insertEntity $ TicketProjectLocal205 tid jid obiid + ) + (Just $ \ (Entity tplidTemp tplTemp) -> do + tars <- selectList ([] :: [Filter TicketAuthorRemote205]) [] + for_ tars $ \ (Entity tarid tar) -> do + tplid <- do + mtplid <- getKeyBy $ UniqueTicketProjectLocal205 $ ticketAuthorRemote205Ticket tar + case mtplid of + Nothing -> error $ "No TicketProjectLocal for tarid#" ++ show tarid + Just k -> return k + update tarid [TicketAuthorRemote205TicketNew =. tplid] + + delete tplidTemp + + let tid = ticketProjectLocal205Ticket tplTemp + _t <- getJust tid + delete tid + + let jid = ticketProjectLocal205Project tplTemp + j <- getJust jid + delete jid + delete $ project205Workflow j + delete $ project205Sharer j + delete $ project205Inbox j + delete $ project205Outbox j + delete $ project205Followers j + + let obiid = ticketProjectLocal205Accept tplTemp + obi <- getJust obiid + delete obiid + delete $ outboxItem205Outbox obi + ) + "ticketNew" + "TicketProjectLocal" + -- 206 + , addUnique "TicketAuthorRemote" $ + Unique "UniqueTicketAuthorRemoteNew" ["ticketNew"] ] migrateDB diff --git a/src/Vervis/Migration/Model.hs b/src/Vervis/Migration/Model.hs index 81b9d14..83ac424 100644 --- a/src/Vervis/Migration/Model.hs +++ b/src/Vervis/Migration/Model.hs @@ -159,6 +159,17 @@ module Vervis.Migration.Model , Ticket201 , Ticket201Generic (..) , TicketProjectLocal201Generic (..) + , Sharer205Generic (..) + , Outbox205Generic (..) + , OutboxItem205Generic (..) + , Inbox205Generic (..) + , FollowerSet205Generic (..) + , Project205Generic (..) + , Workflow205Generic (..) + , Ticket205Generic (..) + , TicketProjectLocal205Generic (..) + , TicketAuthorRemote205 + , TicketAuthorRemote205Generic (..) ) where @@ -314,3 +325,6 @@ model_2020_02_07 = $(schema "2020_02_07_tpl") makeEntitiesMigration "201" $(modelFile "migrations/2020_02_07_tpl_mig.model") + +makeEntitiesMigration "205" + $(modelFile "migrations/2020_02_08_tar_point_to_tpl.model")