mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +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
41 lines
1.6 KiB
Haskell
41 lines
1.6 KiB
Haskell
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
module Hasura.Backends.MSSQL.DDL.Source.Version
|
|
( latestSourceCatalogVersion,
|
|
latestSourceCatalogVersionText,
|
|
previousSourceCatalogVersions,
|
|
setSourceCatalogVersion,
|
|
getSourceCatalogVersion,
|
|
)
|
|
where
|
|
|
|
import Database.MSSQL.Transaction
|
|
import Database.ODBC.SQLServer
|
|
import Database.ODBC.TH qualified as ODBC
|
|
import Hasura.Backends.MSSQL.Connection (MonadMSSQLTx (..))
|
|
import Hasura.Backends.MSSQL.SQL.Error qualified as HGE
|
|
import Hasura.Base.Error
|
|
import Hasura.Prelude
|
|
import Hasura.Server.Migrate.Version
|
|
|
|
latestSourceCatalogVersion :: CatalogVersion
|
|
latestSourceCatalogVersion = CatalogVersion 1
|
|
|
|
latestSourceCatalogVersionText :: Text
|
|
latestSourceCatalogVersionText = tshow latestSourceCatalogVersion
|
|
|
|
previousSourceCatalogVersions :: [CatalogVersion]
|
|
previousSourceCatalogVersions = [CatalogVersion 1 .. pred latestSourceCatalogVersion]
|
|
|
|
setSourceCatalogVersion :: MonadMSSQLTx m => CatalogVersion -> m ()
|
|
setSourceCatalogVersion (CatalogVersion version) =
|
|
liftMSSQLTx $ unitQueryE HGE.defaultMSSQLTxErrorHandler setSourceCatalogVersionQuery
|
|
where
|
|
setSourceCatalogVersionQuery = [ODBC.sql| INSERT INTO hdb_catalog.hdb_source_catalog_version(version, upgraded_on) VALUES ($version, SYSDATETIMEOFFSET()) |]
|
|
setSourceCatalogVersion CatalogVersion08 =
|
|
throw500 "Cannot set the source catalog version to an unstable version."
|
|
|
|
getSourceCatalogVersion :: MonadMSSQLTx m => m CatalogVersion
|
|
getSourceCatalogVersion =
|
|
CatalogVersion <$> liftMSSQLTx (singleRowQueryE HGE.defaultMSSQLTxErrorHandler [ODBC.sql| SELECT version FROM hdb_catalog.hdb_source_catalog_version |])
|