mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
5f38743f29
This came about as I tried to add an instance over catalog versions and found they were just simple integers most of the time (and in one case, a float). I think this change also clarifies how catalog versions work. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4864 GitOrigin-RevId: a6b7db86de564b71a8c2b602bee6a456b8e20d63
52 lines
1.5 KiB
Haskell
52 lines
1.5 KiB
Haskell
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
-- | Postgres DDL Source Version
|
|
--
|
|
-- Deals with catalog version - used by 'Hasura.Backends.Postgres.DDL.Source'.
|
|
module Hasura.Backends.Postgres.DDL.Source.Version
|
|
( latestSourceCatalogVersion,
|
|
latestSourceCatalogVersionText,
|
|
previousSourceCatalogVersions,
|
|
getSourceCatalogVersion,
|
|
setSourceCatalogVersion,
|
|
)
|
|
where
|
|
|
|
import Database.PG.Query qualified as Q
|
|
import Hasura.Backends.Postgres.Connection
|
|
import Hasura.Prelude
|
|
import Hasura.Server.Migrate.Version
|
|
|
|
latestSourceCatalogVersion :: CatalogVersion
|
|
latestSourceCatalogVersion = CatalogVersion 2
|
|
|
|
latestSourceCatalogVersionText :: Text
|
|
latestSourceCatalogVersionText = tshow latestSourceCatalogVersion
|
|
|
|
previousSourceCatalogVersions :: [CatalogVersion]
|
|
previousSourceCatalogVersions = [CatalogVersion 0 .. pred latestSourceCatalogVersion]
|
|
|
|
setSourceCatalogVersion :: MonadTx m => m ()
|
|
setSourceCatalogVersion =
|
|
liftTx $
|
|
Q.unitQE
|
|
defaultTxErrorHandler
|
|
[Q.sql|
|
|
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()
|
|
|]
|
|
(Identity latestSourceCatalogVersionText)
|
|
False
|
|
|
|
getSourceCatalogVersion :: MonadTx m => m Text
|
|
getSourceCatalogVersion =
|
|
liftTx $
|
|
runIdentity . Q.getRow
|
|
<$> Q.withQE
|
|
defaultTxErrorHandler
|
|
[Q.sql| SELECT version FROM hdb_catalog.hdb_source_catalog_version |]
|
|
()
|
|
False
|