From fd704e231feb80661948be5a4a39a7b80aded4c1 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Thu, 6 Feb 2020 03:17:00 +0000 Subject: [PATCH] DB: Add foreign key from TicketAuthorLocal to LocalTicket Right now it's in addition to the Ticket one. The next patch will remove the Ticket old, so TicketAuthorLocal will point only to the LocalTicket. --- config/models | 2 + migrations/2020_02_06_tal_point_to_lt.model | 80 +++++++++++++++++++++ src/Vervis/API.hs | 1 + src/Vervis/Migration.hs | 62 ++++++++++++++++ src/Vervis/Migration/Model.hs | 15 ++++ 5 files changed, 160 insertions(+) create mode 100644 migrations/2020_02_06_tal_point_to_lt.model diff --git a/config/models b/config/models index ec91bb3..7c6d32e 100644 --- a/config/models +++ b/config/models @@ -369,10 +369,12 @@ LocalTicket TicketAuthorLocal ticket TicketId + ticketNew LocalTicketId author PersonId offer OutboxItemId UniqueTicketAuthorLocal ticket + UniqueTicketAuthorLocalNew ticketNew UniqueTicketAuthorLocalOffer offer TicketAuthorRemote diff --git a/migrations/2020_02_06_tal_point_to_lt.model b/migrations/2020_02_06_tal_point_to_lt.model new file mode 100644 index 0000000..09f851b --- /dev/null +++ b/migrations/2020_02_06_tal_point_to_lt.model @@ -0,0 +1,80 @@ +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 + project ProjectId + 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 + accept OutboxItemId + + UniqueTicketAccept accept + +LocalTicket + ticket TicketId + discuss DiscussionId + followers FollowerSetId + + UniqueLocalTicket ticket + UniqueLocalTicketDiscussion discuss + UniqueLocalTicketFollowers followers + +TicketAuthorLocal + ticket TicketId + ticketNew LocalTicketId + author Int64 + offer OutboxItemId + + UniqueTicketAuthorLocal ticket + UniqueTicketAuthorLocalOffer offer + +Discussion diff --git a/src/Vervis/API.hs b/src/Vervis/API.hs index ef5b488..81163f5 100644 --- a/src/Vervis/API.hs +++ b/src/Vervis/API.hs @@ -869,6 +869,7 @@ offerTicketC shrUser summary audience offer@(Offer ticket uTarget) = runExceptT } insert_ TicketAuthorLocal { ticketAuthorLocalTicket = tid + , ticketAuthorLocalTicketNew = ltid , ticketAuthorLocalAuthor = pidAuthor , ticketAuthorLocalOffer = obiid } diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index fa138fb..a41f188 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -73,6 +73,7 @@ import Database.Persist.Local import Vervis.FedURI import Vervis.Model.Ident +import Vervis.Model.Workflow import Vervis.Foundation (App, Route (..)) import Vervis.Migration.Model import Yesod.RenderSource @@ -1252,6 +1253,67 @@ changes hLocal ctx = , removeField "Ticket" "discuss" -- 193 , removeField "Ticket" "followers" + -- 194 + , addFieldRefRequired'' + "TicketAuthorLocal" + (do tid <- do + jid <- do + let temp = "$$temp$$" + sid <- insert $ Sharer194 (text2shr temp) Nothing defaultTime + wid <- insert $ Workflow194 sid (text2wfl temp) Nothing Nothing WSSharer + ibid <- insert Inbox194 + obid <- insert Outbox194 + fsid <- insert FollowerSet194 + insert $ Project194 (text2prj temp) sid Nothing Nothing wid 1 Nothing Nothing Nothing ibid obid fsid + obiid <- do + obid <- insert Outbox194 + let h = Authority "x.y" Nothing :: Host + doc = Doc h emptyActivity + insert $ OutboxItem194 obid (persistJSONObjectFromDoc doc) defaultTime + insert $ Ticket194 jid Nothing defaultTime "" "" "" Nothing "TSNew" defaultTime Nothing obiid + did <- insert Discussion194 + fsid <- insert FollowerSet194 + insertEntity $ LocalTicket194 tid did fsid + ) + (Just $ \ (Entity ltidTemp ltTemp) -> do + tals <- selectList ([] :: [Filter TicketAuthorLocal194]) [] + for_ tals $ \ (Entity talid tal) -> do + tlid <- do + mtlid <- getKeyBy $ UniqueLocalTicket194 $ ticketAuthorLocal194Ticket tal + case mtlid of + Nothing -> error $ "No LocalTicket for talid#" ++ show talid + Just tlid -> return tlid + update talid [TicketAuthorLocal194TicketNew =. tlid] + + delete ltidTemp + + let tid = localTicket194Ticket ltTemp + t <- getJust tid + delete tid + + let jid = ticket194Project t + j <- getJust jid + delete jid + delete $ project194Workflow j + delete $ project194Sharer j + delete $ project194Inbox j + delete $ project194Outbox j + delete $ project194Followers j + + let obiid = ticket194Accept t + obi <- getJust obiid + delete obiid + delete $ outboxItem194Outbox obi + + delete $ localTicket194Discuss ltTemp + + delete $ localTicket194Followers ltTemp + ) + "ticketNew" + "LocalTicket" + -- 195 + , addUnique "TicketAuthorLocal" $ + Unique "UniqueTicketAuthorLocalNew" ["ticketNew"] ] migrateDB diff --git a/src/Vervis/Migration/Model.hs b/src/Vervis/Migration/Model.hs index 3894a6a..5f9d36d 100644 --- a/src/Vervis/Migration/Model.hs +++ b/src/Vervis/Migration/Model.hs @@ -143,6 +143,18 @@ module Vervis.Migration.Model , Ticket189 , Ticket189Generic (..) , LocalTicket189Generic (..) + , Sharer194Generic (..) + , Outbox194Generic (..) + , OutboxItem194Generic (..) + , Inbox194Generic (..) + , FollowerSet194Generic (..) + , Project194Generic (..) + , Workflow194Generic (..) + , Ticket194Generic (..) + , LocalTicket194Generic (..) + , TicketAuthorLocal194 + , TicketAuthorLocal194Generic (..) + , Discussion194Generic (..) ) where @@ -289,3 +301,6 @@ model_2020_02_05 :: [Entity SqlBackend] model_2020_02_05 = $(schema "2020_02_05_local_ticket") makeEntitiesMigration "189" $(modelFile "migrations/2020_02_05_mig.model") + +makeEntitiesMigration "194" + $(modelFile "migrations/2020_02_06_tal_point_to_lt.model")