diff --git a/inferno-ml-server-types/CHANGELOG.md b/inferno-ml-server-types/CHANGELOG.md index 7855d72..3d34593 100644 --- a/inferno-ml-server-types/CHANGELOG.md +++ b/inferno-ml-server-types/CHANGELOG.md @@ -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 diff --git a/inferno-ml-server-types/inferno-ml-server-types.cabal b/inferno-ml-server-types/inferno-ml-server-types.cabal index d976516..9659bd1 100644 --- a/inferno-ml-server-types/inferno-ml-server-types.cabal +++ b/inferno-ml-server-types/inferno-ml-server-types.cabal @@ -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 diff --git a/inferno-ml-server-types/src/Inferno/ML/Server/Types.hs b/inferno-ml-server-types/src/Inferno/ML/Server/Types.hs index f2f9884..4d5292e 100644 --- a/inferno-ml-server-types/src/Inferno/ML/Server/Types.hs +++ b/inferno-ml-server-types/src/Inferno/ML/Server/Types.hs @@ -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, @@ -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 @@ -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 -- @@ -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 @@ -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 ] @@ -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 @@ -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 @@ -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 @@ -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 ] @@ -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" @@ -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 @@ -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 diff --git a/inferno-ml-server/CHANGELOG.md b/inferno-ml-server/CHANGELOG.md index bd4d854..267d3e0 100644 --- a/inferno-ml-server/CHANGELOG.md +++ b/inferno-ml-server/CHANGELOG.md @@ -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 diff --git a/inferno-ml-server/inferno-ml-server.cabal b/inferno-ml-server/inferno-ml-server.cabal index ca96748..4f8fc7a 100644 --- a/inferno-ml-server/inferno-ml-server.cabal +++ b/inferno-ml-server/inferno-ml-server.cabal @@ -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 diff --git a/nix/inferno-ml/migrations/v1-create-tables.sql b/nix/inferno-ml/migrations/v1-create-tables.sql index 7f84bd3..41a2219 100644 --- a/nix/inferno-ml/migrations/v1-create-tables.sql +++ b/nix/inferno-ml/migrations/v1-create-tables.sql @@ -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 @@ -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)