diff --git a/src/Database/Queries.hs b/src/Database/Queries.hs index d17692d..f687662 100644 --- a/src/Database/Queries.hs +++ b/src/Database/Queries.hs @@ -38,11 +38,10 @@ createAppVersion sId VersionInfo{..} = do versionInfoVersion versionInfoReleaseNotes -createMetric :: MonadIO m => Maybe (Key SApp) -> Maybe (Key Version) -> AppIdentifier -> ReaderT SqlBackend m () -createMetric appId versionId event = do +createMetric :: MonadIO m => Key SApp -> Key Version -> ReaderT SqlBackend m () +createMetric appId versionId = do time <- liftIO $ getCurrentTime insert_ $ Metric time appId versionId - event diff --git a/src/Handler/Apps.hs b/src/Handler/Apps.hs index 5bbdd9e..ebe028f 100644 --- a/src/Handler/Apps.hs +++ b/src/Handler/Apps.hs @@ -97,7 +97,7 @@ getApp rootDir ext@(Extension appId) = do av <- runDB $ createAppVersion appKey' versionInfo pure (appKey', av) Just v -> pure (appKey', entityKey v) - runDB $ createMetric (Just appKey) (Just versionKey) appId' + runDB $ createMetric appKey versionKey sz <- liftIO $ fileSize <$> getFileStatus filePath addHeader "Content-Length" (show sz) respondSource typePlain $ CB.sourceFile filePath .| awaitForever sendChunkBS diff --git a/src/Model.hs b/src/Model.hs index ed2f623..98c2fae 100644 --- a/src/Model.hs +++ b/src/Model.hs @@ -30,16 +30,15 @@ Version appId SAppId number AppVersion releaseNotes Text - UniqueNumber number + UniqueBin appId number deriving Eq deriving Show Metric createdAt UTCTime - appId SAppId Maybe default=null - version VersionId Maybe default=null - event Text + appId SAppId + version VersionId deriving Eq deriving Show |] diff --git a/test/Handler/AppSpec.hs b/test/Handler/AppSpec.hs index e3b6167..b1b1b37 100644 --- a/test/Handler/AppSpec.hs +++ b/test/Handler/AppSpec.hs @@ -38,8 +38,9 @@ spec = do setUrl ("/apps/bitcoind.s9pk?spec=0.18.1" :: Text) statusIs 200 apps <- runDBtest $ selectList [SAppAppId ==. "bitcoind"] [] - metrics <- runDBtest $ selectList [MetricEvent ==. "bitcoind"] [] assertEq "app should exist" (length apps) 1 + let app = fromJust $ head apps + metrics <- runDBtest $ selectList [MetricAppId ==. entityKey app] [] assertEq "metric should exist" (length metrics) 1 describe "GET /apps/:appId with existing version spec for cups" $ withApp $ it "creates app and metric records" $ do @@ -48,9 +49,9 @@ spec = do setUrl ("/apps/cups.s9pk?spec=0.2.1" :: Text) statusIs 200 apps <- runDBtest $ selectList [SAppAppId ==. "cups"] [] - metrics <- runDBtest $ selectList [MetricEvent ==. "cups"] [] assertEq "app should exist" (length apps) 1 - assertEq "metric should exist" (length metrics) 1 let app = fromJust $ head apps + metrics <- runDBtest $ selectList [MetricAppId ==. entityKey app] [] + assertEq "metric should exist" (length metrics) 1 version <- runDBtest $ selectList [VersionAppId ==. entityKey app] [] assertEq "version should exist" (length version) 1 \ No newline at end of file