2022-03-16 03:39:21 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
2022-02-24 11:13:19 +03:00
|
|
|
module Hasura.Backends.MSSQL.DDL.Source.Version
|
|
|
|
( latestSourceCatalogVersion,
|
|
|
|
setSourceCatalogVersion,
|
2022-04-21 10:19:37 +03:00
|
|
|
getSourceCatalogVersion,
|
|
|
|
latestSourceCatalogVersionText,
|
2022-02-24 11:13:19 +03:00
|
|
|
)
|
|
|
|
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.Prelude
|
|
|
|
|
|
|
|
latestSourceCatalogVersion :: Int
|
|
|
|
latestSourceCatalogVersion = 1
|
|
|
|
|
2022-04-21 10:19:37 +03:00
|
|
|
latestSourceCatalogVersionText :: Text
|
|
|
|
latestSourceCatalogVersionText = tshow latestSourceCatalogVersion
|
|
|
|
|
2022-02-24 11:13:19 +03:00
|
|
|
setSourceCatalogVersion :: MonadMSSQLTx m => Int -> m ()
|
|
|
|
setSourceCatalogVersion version = liftMSSQLTx $ unitQueryE HGE.defaultMSSQLTxErrorHandler setSourceCatalogVersionQuery
|
|
|
|
where
|
|
|
|
setSourceCatalogVersionQuery = [ODBC.sql| INSERT INTO hdb_catalog.hdb_source_catalog_version(version, upgraded_on) VALUES ($version, SYSDATETIMEOFFSET()) |]
|
2022-04-21 10:19:37 +03:00
|
|
|
|
|
|
|
getSourceCatalogVersion :: MonadMSSQLTx m => m Int
|
|
|
|
getSourceCatalogVersion =
|
|
|
|
liftMSSQLTx $
|
|
|
|
singleRowQueryE HGE.defaultMSSQLTxErrorHandler [ODBC.sql| SELECT version FROM hdb_catalog.hdb_source_catalog_version |]
|