DB: Switch RemoteDiscussion to use RemoteObject instead of instance+ident

This commit is contained in:
fr33domlover 2020-02-08 10:55:19 +00:00
parent fb9e2dd4dd
commit 7612b4e01e
7 changed files with 69 additions and 10 deletions

View file

@ -408,12 +408,11 @@ TicketClaimRequest
Discussion
RemoteDiscussion
instance InstanceId
ident LocalURI
discuss DiscussionId
ident RemoteObjectId
discuss DiscussionId
UniqueRemoteDiscussionIdent instance ident
UniqueRemoteDiscussion discuss
UniqueRemoteDiscussionIdent ident
UniqueRemoteDiscussion discuss
Message
created UTCTime

View file

@ -0,0 +1,19 @@
Instance
host Host
UniqueInstance host
RemoteObject
instance InstanceId
ident LocalURI
UniqueRemoteObject instance ident
RemoteDiscussion
instance InstanceId
ident LocalURI
identNew RemoteObjectId
discuss Int64
UniqueRemoteDiscussionIdent instance ident
UniqueRemoteDiscussion discuss

View file

@ -194,12 +194,13 @@ createNoteC host (Note mluNote luAttrib aud muParent muContext mpublished source
(rd, rdnew) <- lift $ do
let ObjURI hContext luContext = uContext
iid <- either entityKey id <$> insertBy' (Instance hContext)
mrd <- getValBy $ UniqueRemoteDiscussionIdent iid luContext
roid <- either entityKey id <$> insertBy' (RemoteObject iid luContext)
mrd <- getValBy $ UniqueRemoteDiscussionIdent roid
case mrd of
Just rd -> return (rd, False)
Nothing -> do
did <- insert Discussion
let rd = RemoteDiscussion iid luContext did
let rd = RemoteDiscussion roid did
erd <- insertBy' rd
case erd of
Left (Entity _ rd') -> do

View file

@ -131,7 +131,8 @@ sharerCreateNoteF now shrRecip author body (Note mluNote _ _ muParent muContext
Right (ObjURI hContext luContext) -> do
mdid <- lift $ runMaybeT $ do
iid <- MaybeT $ getKeyBy $ UniqueInstance hContext
rd <- MaybeT $ getValBy $ UniqueRemoteDiscussionIdent iid luContext
roid <- MaybeT $ getKeyBy $ UniqueRemoteObject iid luContext
rd <- MaybeT $ getValBy $ UniqueRemoteDiscussionIdent roid
return $ remoteDiscussionDiscuss rd
for_ mparent $ \ parent ->
case parent of

View file

@ -146,8 +146,9 @@ getDiscussionMessage shr lmid = do
ltkhid <- encodeKeyHashid ltid
return $ route2fed $ TicketR shr prj ltkhid
(Nothing, Just rd) -> do
i <- getJust $ remoteDiscussionInstance rd
return $ ObjURI (instanceHost i) (remoteDiscussionIdent rd)
ro <- getJust $ remoteDiscussionIdent rd
i <- getJust $ remoteObjectInstance ro
return $ ObjURI (instanceHost i) (remoteObjectIdent ro)
muParent <- for (messageParent m) $ \ midParent -> do
mlocal <- getBy $ UniqueLocalMessage midParent
mremote <- getValBy $ UniqueRemoteMessage midParent

View file

@ -1421,6 +1421,37 @@ changes hLocal ctx =
"TicketAuthorRemote"
"UniqueTicketAuthorRemoteOffer"
"UniqueTicketAuthorRemoteOpen"
-- 215
, addFieldRefRequired''
"RemoteDiscussion"
(do iid <- insert $ Instance215 $ Authority "215.fake.fake" Nothing
insertEntity $ RemoteObject215 iid $ LocalURI "/fake/215"
)
(Just $ \ (Entity roidTemp roTemp) -> do
rdids <- selectList ([] :: [Filter RemoteDiscussion215]) []
for_ rdids $ \ (Entity rdid rd) -> do
let iid = remoteDiscussion215Instance rd
lu = remoteDiscussion215Ident rd
roid <- insert $ RemoteObject215 iid lu
update rdid [RemoteDiscussion215IdentNew =. roid]
delete roidTemp
delete $ remoteObject215Instance roTemp
)
"identNew"
"RemoteObject"
-- 216
, addUnique "RemoteDiscussion" $
Unique "UniqueRemoteDiscussionIdentNew" ["identNew"]
-- 217
, removeUnique "RemoteDiscussion" "UniqueRemoteDiscussionIdent"
-- 218
, renameUnique "RemoteDiscussion" "UniqueRemoteDiscussionIdentNew" "UniqueRemoteDiscussionIdent"
-- 219
, removeField "RemoteDiscussion" "instance"
-- 220
, removeField "RemoteDiscussion" "ident"
-- 221
, renameField "RemoteDiscussion" "identNew" "ident"
]
migrateDB

View file

@ -170,6 +170,10 @@ module Vervis.Migration.Model
, TicketProjectLocal205Generic (..)
, TicketAuthorRemote205
, TicketAuthorRemote205Generic (..)
, Instance215Generic (..)
, RemoteObject215Generic (..)
, RemoteDiscussion215
, RemoteDiscussion215Generic (..)
)
where
@ -328,3 +332,6 @@ makeEntitiesMigration "201"
makeEntitiesMigration "205"
$(modelFile "migrations/2020_02_08_tar_point_to_tpl.model")
makeEntitiesMigration "215"
$(modelFile "migrations/2020_02_09_rd_point_to_ro.model")