Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[inferno-ml] Add creation date to models and model versions #148

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inferno-ml-server-types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Revision History for inferno-ml-server-types
*Note*: we use https://pvp.haskell.org/ (MAJOR.MAJOR.MINOR.PATCH)

## 0.12.0
* Add creation date to models and versions

## 0.11.0
* Split parameter inputs and outputs

Expand Down
2 changes: 1 addition & 1 deletion inferno-ml-server-types/inferno-ml-server-types.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: inferno-ml-server-types
version: 0.11.0
version: 0.12.0
synopsis: Types for Inferno ML server
description: Types for Inferno ML server
homepage: https://github.com/plow-technologies/inferno.git#readme
Expand Down
17 changes: 17 additions & 0 deletions inferno-ml-server-types/src/Inferno/ML/Server/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ data Model gid = Model
gid :: gid,
-- | Analogous to visibility of @inferno-vc@ scripts
visibility :: VCObjectVisibility,
-- | When the model was created; if left empty, this will be generated
-- automatically when the model is saved
created :: Maybe UTCTime,
-- | The last time the model was updated (i.e. a new version was created),
-- if any
updated :: Maybe UTCTime,
Expand Down Expand Up @@ -334,6 +337,7 @@ instance
<*> fmap getAeson field
<*> field
<*> field
<*> field

instance ToField gid => ToRow (Model gid) where
-- NOTE: Order of fields must align exactly with DB schema
Expand All @@ -345,6 +349,7 @@ instance ToField gid => ToRow (Model gid) where
m.name & toField,
m.gid & toField,
m.visibility & Aeson & toField,
m.created & maybe (toField Default) toField,
-- The `ToRow` instance is only for new rows, so we don't want to set
-- the `updated` and `terminated` fields to anything by default
--
Expand All @@ -368,6 +373,7 @@ instance
<*> o .: "name"
<*> o .: "gid"
<*> o .: "visibility"
<*> o .:? "created"
<*> o .:? "updated"
-- If a new model is being serialized, it does not really make
-- sense to require a `"terminated": null` field
Expand All @@ -381,6 +387,7 @@ instance ToJSON gid => ToJSON (Model gid) where
"name" .= m.name,
"gid" .= m.gid,
"visibility" .= m.visibility,
"created" .= m.created,
"updated" .= m.updated,
"terminated" .= m.terminated
]
Expand All @@ -395,6 +402,7 @@ instance (Ord gid, Arbitrary gid) => Arbitrary (Model gid) where
<*> arbitrary
<*> genMUtc
<*> genMUtc
<*> genMUtc

-- Can't be derived because there is (intentially) no `Arbitrary UTCTime` in scope
instance (Arbitrary gid, Ord gid) => ToADTArbitrary (Model gid) where
Expand Down Expand Up @@ -425,6 +433,9 @@ data ModelVersion gid c = ModelVersion
-- the PSQL large object table
contents :: c,
version :: Version,
-- | When the model version was created; if left empty, this will be generated
-- automatically when the model version is saved
created :: Maybe UTCTime,
-- | The time that this model version was \"deleted\", if any. For active
-- models versions, this will be @Nothing@
terminated :: Maybe UTCTime
Expand All @@ -446,6 +457,7 @@ instance FromField gid => FromRow (ModelVersion gid Oid) where
<*> field
<*> field
<*> field
<*> field

instance ToField gid => ToRow (ModelVersion gid Oid) where
-- NOTE: Order of fields must align exactly with DB schema
Expand All @@ -456,6 +468,7 @@ instance ToField gid => ToRow (ModelVersion gid Oid) where
mv.card & Aeson & toField,
mv.contents & toField,
mv.version & toField,
mv.created & maybe (toField Default) toField,
toField Default
]

Expand All @@ -469,6 +482,8 @@ instance FromJSON gid => FromJSON (ModelVersion gid Oid) where
<*> o .: "card"
<*> fmap (Oid . fromIntegral @Word64) (o .: "contents")
<*> o .: "version"
-- Will be absent when saving new model version
<*> o .:? "created"
-- If a new model version is being serialized, it does not really make
-- sense to require a `"terminated": null` field
<*> o .:? "terminated"
Expand All @@ -483,6 +498,7 @@ instance ToJSON gid => ToJSON (ModelVersion gid Oid) where
"contents" .= unOid mv.contents,
"version" .= mv.version,
"card" .= mv.card,
"created" .= mv.created,
"terminated" .= mv.terminated
]
where
Expand All @@ -500,6 +516,7 @@ instance Arbitrary c => Arbitrary (ModelVersion gid c) where
<*> arbitrary
<*> arbitrary
<*> genMUtc
<*> genMUtc

-- Can't be derived because there is (intentially) no `Arbitrary UTCTime` in scope
instance Arbitrary c => ToADTArbitrary (ModelVersion gid c) where
Expand Down
3 changes: 3 additions & 0 deletions inferno-ml-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Revision History for `inferno-ml-server`

## 2023.11.26
* Add creation date to models and versions

## 2023.10.18
* Add new testing route
* Some improvements to model caching
Expand Down
2 changes: 1 addition & 1 deletion inferno-ml-server/inferno-ml-server.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: inferno-ml-server
version: 2023.10.18
version: 2023.11.26
synopsis: Server for Inferno ML
description: Server for Inferno ML
homepage: https://github.com/plow-technologies/inferno.git#readme
Expand Down
2 changes: 2 additions & 0 deletions nix/inferno-ml/migrations/v1-create-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ create table if not exists models
, name text not null
, gid numeric not null
, visibility jsonb
, created timestamptz default now()
-- May be missing, if there is no model version yet
, updated timestamptz
-- See note above
Expand All @@ -42,6 +43,7 @@ create table if not exists mversions
-- the contents
, contents oid not null
, version text not null
, created timestamptz default now()
-- See note above
, terminated timestamptz
, unique (version, model)
Expand Down
Loading