From 5e9dd3555d372d394c283a4c2573392d92a2caac Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sat, 8 Feb 2020 11:49:30 +0000 Subject: [PATCH] DB: Add and populate TicketUnderProject table A row in this table will be required for local-project-local-author tickets hosted under the project, and non-existence of a row will be required for such tickets hosted by the author. So I'll need to CAREFULLY update all the ticket route handler code and all the ticket related AP code. The latter includes C2S and S2S for tickets, ticket deps, ticket discussion... everything that is under tickets. --- config/models | 6 ++++++ migrations/2020_02_09_tup.model | 5 +++++ migrations/2020_02_09_tup_mig.model | 32 +++++++++++++++++++++++++++++ src/Vervis/Migration.hs | 12 +++++++++++ src/Vervis/Migration/Model.hs | 8 ++++++++ 5 files changed, 63 insertions(+) create mode 100644 migrations/2020_02_09_tup.model create mode 100644 migrations/2020_02_09_tup_mig.model diff --git a/config/models b/config/models index db79a76..6bcabf1 100644 --- a/config/models +++ b/config/models @@ -388,6 +388,12 @@ TicketAuthorRemote UniqueTicketAuthorRemote ticket UniqueTicketAuthorRemoteOpen open +TicketUnderProject + project TicketProjectLocalId + author TicketAuthorLocalId + + UniqueTicketUnderProject project author + TicketDependency parent TicketId child TicketId diff --git a/migrations/2020_02_09_tup.model b/migrations/2020_02_09_tup.model new file mode 100644 index 0000000..390050d --- /dev/null +++ b/migrations/2020_02_09_tup.model @@ -0,0 +1,5 @@ +TicketUnderProject + project TicketProjectLocalId + author TicketAuthorLocalId + + UniqueTicketUnderProject project author diff --git a/migrations/2020_02_09_tup_mig.model b/migrations/2020_02_09_tup_mig.model new file mode 100644 index 0000000..f8059a9 --- /dev/null +++ b/migrations/2020_02_09_tup_mig.model @@ -0,0 +1,32 @@ +Ticket + +LocalTicket + ticket TicketId + discuss Int64 + followers Int64 + + UniqueLocalTicket ticket + UniqueLocalTicketDiscussion discuss + UniqueLocalTicketFollowers followers + +TicketProjectLocal + ticket TicketId + project Int64 + accept Int64 + + UniqueTicketProjectLocal ticket + UniqueTicketProjectLocalAccept accept + +TicketAuthorLocal + ticket LocalTicketId + author Int64 + open Int64 + + UniqueTicketAuthorLocal ticket + UniqueTicketAuthorLocalOpen open + +TicketUnderProject + project TicketProjectLocalId + author TicketAuthorLocalId + + UniqueTicketUnderProject project author diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index e3fb4cf..003d88d 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -26,6 +26,7 @@ import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Maybe import Control.Monad.Trans.Reader (ReaderT, runReaderT) import Data.Aeson +import Data.Bifunctor import Data.ByteString (ByteString) import Data.Default.Class import Data.Default.Instances.ByteString () @@ -1452,6 +1453,17 @@ changes hLocal ctx = , removeField "RemoteDiscussion" "ident" -- 221 , renameField "RemoteDiscussion" "identNew" "ident" + -- 222 + , addEntities model_2020_02_09 + -- 223 + , unchecked $ lift $ do + ids <- E.select $ E.from $ + \ (tal `E.InnerJoin` lt `E.InnerJoin` t `E.InnerJoin` tpl) -> do + E.on $ t E.^. Ticket223Id E.==. tpl E.^. TicketProjectLocal223Ticket + E.on $ lt E.^. LocalTicket223Ticket E.==. t E.^. Ticket223Id + E.on $ tal E.^. TicketAuthorLocal223Ticket E.==. lt E.^. LocalTicket223Id + return (tpl E.^. TicketProjectLocal223Id, tal E.^. TicketAuthorLocal223Id) + insertMany_ $ map (uncurry TicketUnderProject223 . bimap E.unValue E.unValue) ids ] migrateDB diff --git a/src/Vervis/Migration/Model.hs b/src/Vervis/Migration/Model.hs index 016f518..c3d4c94 100644 --- a/src/Vervis/Migration/Model.hs +++ b/src/Vervis/Migration/Model.hs @@ -174,6 +174,8 @@ module Vervis.Migration.Model , RemoteObject215Generic (..) , RemoteDiscussion215 , RemoteDiscussion215Generic (..) + , model_2020_02_09 + , TicketUnderProject223Generic (..) ) where @@ -335,3 +337,9 @@ makeEntitiesMigration "205" makeEntitiesMigration "215" $(modelFile "migrations/2020_02_09_rd_point_to_ro.model") + +model_2020_02_09 :: [Entity SqlBackend] +model_2020_02_09 = $(schema "2020_02_09_tup") + +makeEntitiesMigration "223" + $(modelFile "migrations/2020_02_09_tup_mig.model")