2021-06-01 20:33:25 +03:00
|
|
|
module Hasura.Backends.Postgres.DDL.Source.Version where
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Database.PG.Query qualified as Q
|
|
|
|
import Hasura.Backends.Postgres.Connection
|
|
|
|
import Hasura.Prelude
|
2021-06-01 20:33:25 +03:00
|
|
|
|
|
|
|
latestSourceCatalogVersion :: Integer
|
|
|
|
latestSourceCatalogVersion = 2
|
|
|
|
|
|
|
|
latestSourceCatalogVersionText :: Text
|
|
|
|
latestSourceCatalogVersionText = tshow latestSourceCatalogVersion
|
|
|
|
|
|
|
|
setSourceCatalogVersion :: MonadTx m => m ()
|
2021-09-24 01:56:37 +03:00
|
|
|
setSourceCatalogVersion =
|
|
|
|
liftTx $
|
|
|
|
Q.unitQE
|
|
|
|
defaultTxErrorHandler
|
|
|
|
[Q.sql|
|
2021-06-01 20:33:25 +03:00
|
|
|
INSERT INTO hdb_catalog.hdb_source_catalog_version(version, upgraded_on)
|
|
|
|
VALUES ($1, NOW())
|
|
|
|
ON CONFLICT ((version IS NOT NULL))
|
|
|
|
DO UPDATE SET version = $1, upgraded_on = NOW()
|
2021-09-24 01:56:37 +03:00
|
|
|
|]
|
|
|
|
(Identity latestSourceCatalogVersionText)
|
|
|
|
False
|
2021-06-01 20:33:25 +03:00
|
|
|
|
|
|
|
getSourceCatalogVersion :: MonadTx m => m Text
|
2021-09-24 01:56:37 +03:00
|
|
|
getSourceCatalogVersion =
|
|
|
|
liftTx $
|
|
|
|
runIdentity . Q.getRow
|
|
|
|
<$> Q.withQE
|
|
|
|
defaultTxErrorHandler
|
|
|
|
[Q.sql| SELECT version FROM hdb_catalog.hdb_source_catalog_version |]
|
|
|
|
()
|
|
|
|
False
|