From dbbe052cd16e3e162c8a50c6de20a9f39fd3049c Mon Sep 17 00:00:00 2001 From: GitBluub Date: Fri, 25 Feb 2022 11:42:31 +0100 Subject: [PATCH] feat: utc time nullable --- api/sql/dump.sql | 3 ++- api/src/Db/Pipeline.hs | 6 +++--- api/src/Utils.hs | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/sql/dump.sql b/api/sql/dump.sql index 291aa62..9dcdf1f 100644 --- a/api/sql/dump.sql +++ b/api/sql/dump.sql @@ -15,10 +15,11 @@ CREATE TABLE IF NOT EXISTS pipelines ( enabled BOOLEAN NOT NULL, error TEXT NOT NULL, trigger_count INTEGER NOT NULL, - last_trigger TIMESTAMP NOT NULL, + last_trigger TIMESTAMP, CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) + ON DELETE CASCADE ); CREATE TABLE IF NOT EXISTS reactions ( diff --git a/api/src/Db/Pipeline.hs b/api/src/Db/Pipeline.hs index da75336..44129e6 100644 --- a/api/src/Db/Pipeline.hs +++ b/api/src/Db/Pipeline.hs @@ -22,7 +22,7 @@ import Data.Text (Text) import GHC.Generics (Generic) import Rel8 (Column, DBEq, DBType, Expr, Insert (Insert, returning), JSONBEncoded (JSONBEncoded), Name, OnConflict (DoNothing), Query, ReadShow (ReadShow), Rel8able, Result, Returning (Projection, NumberOfRowsAffected), TableSchema (TableSchema, columns, name, schema), each, into, lit, nextval, onConflict, returning, rows, unsafeCastExpr, values, where_, (==.), Update (Update, from, returning, set, target, updateWhere), target, from, Delete (Delete, deleteWhere, from, returning, using), target, from, using) -import Core.Pipeline +import Core.Pipeline ( PipelineParams, PipelineType ) import Data.Functor.Identity (Identity) import Servant (FromHttpApiData) import Core.User (UserId(UserId)) @@ -41,7 +41,7 @@ data Pipeline f = Pipeline , pipelineEnabled :: Column f Bool , pipelineError :: Column f Text , pipelineTriggerCount :: Column f Int64 - , pipelineLastTrigger :: Column f UTCTime + , pipelineLastTrigger :: Column f (Maybe UTCTime) } deriving stock (Generic) deriving anyclass (Rel8able) @@ -100,7 +100,7 @@ insertPipeline (Pipeline _ name type' params uid _ _ _ _) = , pipelineEnabled = lit True , pipelineError = lit "" , pipelineTriggerCount = lit 0 - , pipelineLastTrigger = lit $ UTCTime (fromGregorian 0 0 0) (secondsToDiffTime 0) + , pipelineLastTrigger = lit Nothing } ] , onConflict = DoNothing diff --git a/api/src/Utils.hs b/api/src/Utils.hs index 5f78934..10f6fa9 100644 --- a/api/src/Utils.hs +++ b/api/src/Utils.hs @@ -9,12 +9,13 @@ import qualified Servant.Auth as Servant.Auth.Server import Servant.Auth (JWT) import Db.User (User') import qualified Servant.Auth.Server -import Core.User (User) +import Core.User (User, UserId (UserId)) import Data.Text (Text, unpack) import Data.HashMap.Strict (HashMap, lookup) import Data.Functor.Identity (Identity) import Db.Pipeline (Pipeline (Pipeline), PipelineId (PipelineId), pipelineLastTrigger, pipelineTriggerCount, pipelineError, pipelineEnabled, pipelineUserId, pipelineParams, pipelineType, pipelineName, pipelineId) -import Core.Pipeline (PipelineType(TwitterNewPost), PipelineParams (TwitterNewPostP)) +import Core.Pipeline (PipelineType(TwitterNewPost), PipelineParams (TwitterNewPostP), TwitterNewPostData (TwitterNewPostData)) +import Data.Time (UTCTime (UTCTime), fromGregorian, secondsToDiffTime) mapInd :: (a -> Int -> b) -> [a] -> [b] @@ -38,7 +39,7 @@ defaultPipeline = Pipeline , pipelineEnabled = True , pipelineError = "" , pipelineTriggerCount = 0 - , pipelineLastTrigger = UTCTime (fromGregorian 0 0 0) (secondsToDiffTime 0) + , pipelineLastTrigger = Nothing } type UserAuth = Servant.Auth.Server.Auth '[JWT] User