1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 15:34:51 +09:00

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.
This commit is contained in:
fr33domlover 2020-02-06 03:17:00 +00:00
parent 443ff6daa1
commit fd704e231f
5 changed files with 160 additions and 0 deletions

View file

@ -369,10 +369,12 @@ LocalTicket
TicketAuthorLocal TicketAuthorLocal
ticket TicketId ticket TicketId
ticketNew LocalTicketId
author PersonId author PersonId
offer OutboxItemId offer OutboxItemId
UniqueTicketAuthorLocal ticket UniqueTicketAuthorLocal ticket
UniqueTicketAuthorLocalNew ticketNew
UniqueTicketAuthorLocalOffer offer UniqueTicketAuthorLocalOffer offer
TicketAuthorRemote TicketAuthorRemote

View file

@ -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

View file

@ -869,6 +869,7 @@ offerTicketC shrUser summary audience offer@(Offer ticket uTarget) = runExceptT
} }
insert_ TicketAuthorLocal insert_ TicketAuthorLocal
{ ticketAuthorLocalTicket = tid { ticketAuthorLocalTicket = tid
, ticketAuthorLocalTicketNew = ltid
, ticketAuthorLocalAuthor = pidAuthor , ticketAuthorLocalAuthor = pidAuthor
, ticketAuthorLocalOffer = obiid , ticketAuthorLocalOffer = obiid
} }

View file

@ -73,6 +73,7 @@ import Database.Persist.Local
import Vervis.FedURI import Vervis.FedURI
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Workflow
import Vervis.Foundation (App, Route (..)) import Vervis.Foundation (App, Route (..))
import Vervis.Migration.Model import Vervis.Migration.Model
import Yesod.RenderSource import Yesod.RenderSource
@ -1252,6 +1253,67 @@ changes hLocal ctx =
, removeField "Ticket" "discuss" , removeField "Ticket" "discuss"
-- 193 -- 193
, removeField "Ticket" "followers" , 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 migrateDB

View file

@ -143,6 +143,18 @@ module Vervis.Migration.Model
, Ticket189 , Ticket189
, Ticket189Generic (..) , Ticket189Generic (..)
, LocalTicket189Generic (..) , LocalTicket189Generic (..)
, Sharer194Generic (..)
, Outbox194Generic (..)
, OutboxItem194Generic (..)
, Inbox194Generic (..)
, FollowerSet194Generic (..)
, Project194Generic (..)
, Workflow194Generic (..)
, Ticket194Generic (..)
, LocalTicket194Generic (..)
, TicketAuthorLocal194
, TicketAuthorLocal194Generic (..)
, Discussion194Generic (..)
) )
where where
@ -289,3 +301,6 @@ model_2020_02_05 :: [Entity SqlBackend]
model_2020_02_05 = $(schema "2020_02_05_local_ticket") model_2020_02_05 = $(schema "2020_02_05_local_ticket")
makeEntitiesMigration "189" $(modelFile "migrations/2020_02_05_mig.model") makeEntitiesMigration "189" $(modelFile "migrations/2020_02_05_mig.model")
makeEntitiesMigration "194"
$(modelFile "migrations/2020_02_06_tal_point_to_lt.model")