aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuebinm2022-06-16 02:46:37 +0200
committerstuebinm2022-06-16 02:46:37 +0200
commit03375da1edca5eb46477c78c76ef609e99b17205 (patch)
tree10cd5db94c3eb2a91a60cb67041db78baa3a4d88
parent8feb2556eda0604b6710309bf7ffddb72c22fc4a (diff)
a couple more database schemas
might eventually be needed; until then they're just scaffolding so I don't loose sight of things
-rw-r--r--lib/Persist.hs33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/Persist.hs b/lib/Persist.hs
index 3115ce3..9486a1d 100644
--- a/lib/Persist.hs
+++ b/lib/Persist.hs
@@ -40,12 +40,12 @@ import Data.Pool (Pool)
import Data.Time (NominalDiffTime,
UTCTime (utctDay), addUTCTime,
dayOfWeek, diffUTCTime,
- getCurrentTime, nominalDay)
+ getCurrentTime, nominalDay, TimeOfDay)
import Database.Persist.Postgresql (SqlBackend)
import GHC.Generics (Generic)
import Web.PathPieces (PathPiece)
-
-
+import Data.Vector (Vector)
+import Data.Time.Calendar (Day, DayOfWeek (..))
newtype Token = Token UUID
deriving newtype
@@ -57,8 +57,12 @@ instance ToSchema Token where
instance ToParamSchema Token where
toParamSchema _ = toParamSchema (Proxy @String)
+data AmendmentStatus = Cancelled | Added
+ deriving (ToJSON, FromJSON, Generic, Show, Read, Eq)
+derivePersistField "AmendmentStatus"
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
+-- | tokens which have been issued
RunningTrip sql=tt_tracker_token
Id Token default=uuid_generate_v4()
expires UTCTime
@@ -68,12 +72,31 @@ RunningTrip sql=tt_tracker_token
TripPing json sql=tt_trip_ping
token RunningTripId
- latitude Double
- longitude Double
+ lat Double
+ long Double
delay Double
timestamp UTCTime
deriving Show Generic Eq
+Announcements sql=tt_announcements
+ trip TripID
+ message Text
+ day Text
+
+-- | this table works as calendar_dates.txt in GTFS
+ScheduleAmendment json sql=tt_schedule_amendement
+ trip TripID
+ day Text
+ status AmendmentStatus
+ -- only one special rule per TripID and Day (else incoherent)
+ TripAndDay trip day
+
+-- TODO: possible to have regular trips moved in time without changing TripID?
+ExtraordinaryTrip sql=tt_extra_trip
+ trip TripID
+ day Text
+ stops (Vector Text)
+ stopTimes (Vector TimeOfDay)
|]
instance ToSchema RunningTripId where