graphql-engine/server/src-lib/Hasura/Backends/Postgres/DDL/Source/Version.hs
jkachmar 647231b685 Yeet some default-extensions
Manually enables:
* EmptyCase
* ExistentialQuantification
* QuantifiedConstraints
* QuasiQuotes
* TemplateHaskell
* TypeFamilyDependencies

...in the following components:
* 'graphql-engine' library
* 'graphql-engine' 'src-test'
* 'graphql-engine' 'tests/integration'
* 'graphql-engine' tests-hspec'

Additionally, performs some light refactoring and documentation.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3991
GitOrigin-RevId: 514477d3466b01f60eca8935d0fef60dd0756838
2022-03-16 00:40:17 +00:00

47 lines
1.2 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
( getSourceCatalogVersion,
latestSourceCatalogVersion,
latestSourceCatalogVersionText,
setSourceCatalogVersion,
)
where
import Database.PG.Query qualified as Q
import Hasura.Backends.Postgres.Connection
import Hasura.Prelude
latestSourceCatalogVersion :: Integer
latestSourceCatalogVersion = 2
latestSourceCatalogVersionText :: Text
latestSourceCatalogVersionText = tshow 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