mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 21:12:09 +03:00
d33025ff5b
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4766 GitOrigin-RevId: 1c1bf173e53fd0b6692131632023817dc843b302
54 lines
2.0 KiB
Haskell
54 lines
2.0 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 2
|
|
|
|
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|
|
|
BEGIN TRANSACTION
|
|
IF EXISTS (select 1 from hdb_catalog.hdb_source_catalog_version WITH (UPDLOCK,SERIALIZABLE))
|
|
BEGIN
|
|
UPDATE hdb_catalog.hdb_source_catalog_version
|
|
SET version = $version, upgraded_on = SYSDATETIMEOFFSET()
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
INSERT INTO hdb_catalog.hdb_source_catalog_version (version, upgraded_on)
|
|
values ($version, SYSDATETIMEOFFSET())
|
|
END
|
|
COMMIT TRANSACTION
|
|
|]
|
|
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 |])
|