From 7aeb39861887bd76ba35e5cf5222ddf08df68045 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 16 May 2024 23:07:51 +0200 Subject: Persist: add cascade rules to foreign keys It turns out persist does support these, they're just not mentioned in the yesod book. (for future reference, the syntax is defined in Database.Persist.Quasi, which does include some documentation [1]) [1] https://hackage.haskell.org/package/persistent-2.14.6.1/docs/Database-Persist-Quasi.html --- lib/Persist.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/Persist.hs b/lib/Persist.hs index f722487..637155a 100644 --- a/lib/Persist.hs +++ b/lib/Persist.hs @@ -103,7 +103,7 @@ Import sql=tt_imports date UTCTime Stop sql=tt_stop - ticket TicketId + ticket TicketId OnDeleteCascade OnUpdateCascade station StationId arrival GTFS.Time departure GTFS.Time @@ -131,25 +131,23 @@ Tracker sql=tt_tracker_token deriving Eq Show Generic TrackerTicket - ticket TicketId - tracker TrackerId + ticket TicketId OnDeleteCascade OnUpdateCascade + tracker TrackerId OnDeleteCascade OnUpdateCascade UniqueTrackerTicket ticket tracker - -- raw frames as received from OBUs TrainPing json sql=tt_trip_ping - -- ticket TicketId - token TrackerId + ticket TicketId OnDeleteCascade OnUpdateCascade + token TrackerId OnDeleteSetNull OnUpdateCascade geopos Geopos timestamp UTCTime sequence Double - ticket TicketId deriving Show Generic Eq -- status of a train somewhen in time (may be in the future), -- inferred from trainpings / entered via controlRoom TrainAnchor json sql=tt_trip_anchor - ticket TicketId + ticket TicketId OnDeleteCascade OnUpdateCascade created UTCTime when GTFS.Seconds sequence Double @@ -160,7 +158,7 @@ TrainAnchor json sql=tt_trip_anchor -- TODO: multi-language support? Announcement json sql=tt_announcements Id UUID default=uuid_generate_v4() - ticket TicketId + ticket TicketId OnDeleteCascade OnUpdateCascade header Text message Text url Text Maybe -- cgit v1.2.3