2022-03-16 03:39:21 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
2022-02-08 12:24:34 +03:00
|
|
|
-- | Postgres DDL Source Version
|
|
|
|
--
|
|
|
|
-- Deals with catalog version - used by 'Hasura.Backends.Postgres.DDL.Source'.
|
2021-11-04 19:08:33 +03:00
|
|
|
module Hasura.Backends.Postgres.DDL.Source.Version
|
2022-06-29 11:18:32 +03:00
|
|
|
( latestSourceCatalogVersion,
|
2021-11-04 19:08:33 +03:00
|
|
|
latestSourceCatalogVersionText,
|
2022-06-29 11:18:32 +03:00
|
|
|
previousSourceCatalogVersions,
|
|
|
|
getSourceCatalogVersion,
|
2021-11-04 19:08:33 +03:00
|
|
|
setSourceCatalogVersion,
|
|
|
|
)
|
|
|
|
where
|
2021-06-01 20:33:25 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Database.PG.Query qualified as Q
|
|
|
|
import Hasura.Backends.Postgres.Connection
|
|
|
|
import Hasura.Prelude
|
2022-06-29 11:18:32 +03:00
|
|
|
import Hasura.Server.Migrate.Version
|
2021-06-01 20:33:25 +03:00
|
|
|
|
2022-06-29 11:18:32 +03:00
|
|
|
latestSourceCatalogVersion :: CatalogVersion
|
|
|
|
latestSourceCatalogVersion = CatalogVersion 2
|
2021-06-01 20:33:25 +03:00
|
|
|
|
|
|
|
latestSourceCatalogVersionText :: Text
|
|
|
|
latestSourceCatalogVersionText = tshow latestSourceCatalogVersion
|
|
|
|
|
2022-06-29 11:18:32 +03:00
|
|
|
previousSourceCatalogVersions :: [CatalogVersion]
|
|
|
|
previousSourceCatalogVersions = [CatalogVersion 0 .. pred latestSourceCatalogVersion]
|
|
|
|
|
2021-06-01 20:33:25 +03:00
|
|
|
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
|