From 6e2445a31fc2ab9a46d803fffcac2acba8f46720 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Fri, 7 Feb 2020 23:05:42 +0000 Subject: [PATCH] DB: Remove unnecessary fkey from TicketAuthorRemote to Ticket Since it points to TicketProjectLocal which in turn points to Ticket. --- config/models | 6 ++---- src/Vervis/Federation/Ticket.hs | 3 +-- src/Vervis/Handler/Ticket.hs | 8 +++++--- src/Vervis/Migration.hs | 11 +++++++++++ src/Vervis/Ticket.hs | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/config/models b/config/models index 39315d9..dca8432 100644 --- a/config/models +++ b/config/models @@ -381,13 +381,11 @@ TicketAuthorLocal UniqueTicketAuthorLocalOffer offer TicketAuthorRemote - ticket TicketId - ticketNew TicketProjectLocalId + ticket TicketProjectLocalId author RemoteActorId offer RemoteActivityId - UniqueTicketAuthorRemote ticket - UniqueTicketAuthorRemoteNew ticketNew + UniqueTicketAuthorRemote ticket UniqueTicketAuthorRemoteOffer offer TicketDependency diff --git a/src/Vervis/Federation/Ticket.hs b/src/Vervis/Federation/Ticket.hs index 5139314..3ffb384 100644 --- a/src/Vervis/Federation/Ticket.hs +++ b/src/Vervis/Federation/Ticket.hs @@ -284,8 +284,7 @@ projectOfferTicketF , ticketProjectLocalAccept = obiidAccept } insert_ TicketAuthorRemote - { ticketAuthorRemoteTicket = tid - , ticketAuthorRemoteTicketNew = tplid + { ticketAuthorRemoteTicket = tplid , ticketAuthorRemoteAuthor = raidAuthor , ticketAuthorRemoteOffer = ractid } diff --git a/src/Vervis/Handler/Ticket.hs b/src/Vervis/Handler/Ticket.hs index 73abfac..62573e2 100644 --- a/src/Vervis/Handler/Ticket.hs +++ b/src/Vervis/Handler/Ticket.hs @@ -260,7 +260,7 @@ getTicketR shar proj ltkhid = do ltid <- decodeKeyHashid404 ltkhid lticket <- get404 ltid let tid = localTicketTicket lticket - tpl <- getValBy404 $ UniqueTicketProjectLocal tid + Entity tplid tpl <- getBy404 $ UniqueTicketProjectLocal tid unless (ticketProjectLocalProject tpl == jid) notFound author <- requireEitherAlt @@ -269,7 +269,7 @@ getTicketR shar proj ltkhid = do p <- getJust $ ticketAuthorLocalAuthor tal getJust $ personIdent p ) - (do mtar <- getValBy $ UniqueTicketAuthorRemote tid + (do mtar <- getValBy $ UniqueTicketAuthorRemote tplid for mtar $ \ tar -> do ra <- getJust $ ticketAuthorRemoteAuthor tar ro <- getJust $ remoteActorIdent ra @@ -954,16 +954,18 @@ getTicketDeps forward shr prj ltkhid = do \ ( td `E.InnerJoin` t `E.InnerJoin` lt + `E.InnerJoin` tpl `E.LeftOuterJoin` (tal `E.InnerJoin` p `E.InnerJoin` s) `E.LeftOuterJoin` (tar `E.InnerJoin` ra `E.InnerJoin` ro `E.InnerJoin` i) ) -> do E.on $ ro E.?. RemoteObjectInstance E.==. i E.?. InstanceId E.on $ ra E.?. RemoteActorIdent E.==. ro E.?. RemoteObjectId E.on $ tar E.?. TicketAuthorRemoteAuthor E.==. ra E.?. RemoteActorId - E.on $ E.just (t E.^. TicketId) E.==. tar E.?. TicketAuthorRemoteTicket + E.on $ E.just (tpl E.^. TicketProjectLocalId) E.==. tar E.?. TicketAuthorRemoteTicket E.on $ p E.?. PersonIdent E.==. s E.?. SharerId E.on $ tal E.?. TicketAuthorLocalAuthor E.==. p E.?. PersonId E.on $ E.just (lt E.^. LocalTicketId) E.==. tal E.?. TicketAuthorLocalTicket + E.on $ t E.^. TicketId E.==. tpl E.^. TicketProjectLocalTicket E.on $ t E.^. TicketId E.==. lt E.^. LocalTicketTicket E.on $ td E.^. to' E.==. t E.^. TicketId E.where_ $ td E.^. from' E.==. E.val tid diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 6b4040d..7f913c5 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -1396,6 +1396,17 @@ changes hLocal ctx = -- 206 , addUnique "TicketAuthorRemote" $ Unique "UniqueTicketAuthorRemoteNew" ["ticketNew"] + -- 207 + , removeUnique "TicketAuthorRemote" "UniqueTicketAuthorRemote" + -- 208 + , removeField "TicketAuthorRemote" "ticket" + -- 209 + , renameUnique + "TicketAuthorRemote" + "UniqueTicketAuthorRemoteNew" + "UniqueTicketAuthorRemote" + -- 210 + , renameField "TicketAuthorRemote" "ticketNew" "ticket" ] migrateDB diff --git a/src/Vervis/Ticket.hs b/src/Vervis/Ticket.hs index eff9a54..0b675b6 100644 --- a/src/Vervis/Ticket.hs +++ b/src/Vervis/Ticket.hs @@ -65,7 +65,7 @@ getTicketSummaries mfilt morder offlim jid = do on $ ro ?. RemoteObjectInstance ==. i ?. InstanceId on $ ra ?. RemoteActorIdent ==. ro ?. RemoteObjectId on $ tar ?. TicketAuthorRemoteAuthor ==. ra ?. RemoteActorId - on $ just (t ^. TicketId) ==. tar ?. TicketAuthorRemoteTicket + on $ just (tpl ^. TicketProjectLocalId) ==. tar ?. TicketAuthorRemoteTicket on $ p ?. PersonIdent ==. s ?. SharerId on $ tal ?. TicketAuthorLocalAuthor ==. p ?. PersonId on $ just (lt ^. LocalTicketId) ==. tal ?. TicketAuthorLocalTicket