From 200c1019c4fba3ecd8330da4de15806dfd59fd0a Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 10 Nov 2024 15:36:10 +0000 Subject: [PATCH] separate migrations for Point and Session --- app/Main.hs | 3 ++- lib/Store.hs | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 1d64200..197d662 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -159,6 +159,7 @@ connStr = "host=127.0.0.1 port=5432 user=souplesse dbname=souplesse password=sec main :: IO () main = runStderrLoggingT $ withPostgresqlPool connStr 10 $ \pool -> liftIO $ do runResourceT $ flip runSqlPool pool $ do - runMigration migrateAll + runMigration migrateSession + runMigration migrateTrkpt static' <- static "frontend" warp 3000 $ Souplesse pool static' diff --git a/lib/Store.hs b/lib/Store.hs index 7c6d73b..60250aa 100644 --- a/lib/Store.hs +++ b/lib/Store.hs @@ -13,7 +13,9 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -module Store (save, fetch, sessions, sessionStartTime, sessionDuration, migrateAll) where +module Store (save, fetch, sessions, sessionStartTime, + sessionDuration, migrateSession, migrateTrkpt + ) where import Control.Exception import Control.Monad.IO.Class (MonadIO, liftIO) @@ -43,7 +45,17 @@ connString :: ConnectionString connString = "host=127.0.0.1 port=5432 user=souplesse dbname=souplesse password=secret" share - [mkPersist sqlSettings, mkMigrate "migrateAll"] + [mkPersist sqlSettings, mkMigrate "migrateSession"] + [persistLowerCase| +Session + startTime UTCTime + duration PgInterval + draft Bool default=True + notes String Maybe +|] + +share + [mkPersist sqlSettings, mkMigrate "migrateTrkpt"] [persistLowerCase| Trkpt lat Double @@ -53,14 +65,9 @@ Trkpt cadence Int Maybe power Int Maybe heartRate Int Maybe - -Session - startTime UTCTime - duration PgInterval - draft Bool default=True - notes String Maybe |] + fromPoint :: Point -> Trkpt fromPoint p = let Pos lat lon ele = T.pos p