mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
15071a3bc9
Relates to https://github.com/hasura/graphql-engine/issues/7755 This includes: 1. SQL Server 2. Citus And removes the persistent-based testing in favor of duplicating the schema setup, data insertion and teardown. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3030 Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com> GitOrigin-RevId: ab03e68436d2ae07a9ddeb5a499ff41e48d0e2d6
58 lines
1.5 KiB
Haskell
58 lines
1.5 KiB
Haskell
{-# OPTIONS -Wno-redundant-constraints #-}
|
|
|
|
-- | SQLServer helpers.
|
|
module Harness.Sqlserver
|
|
( livenessCheck,
|
|
run_,
|
|
)
|
|
where
|
|
|
|
import Control.Concurrent
|
|
import Control.Exception
|
|
import Control.Monad.Reader
|
|
import Data.String
|
|
import Database.ODBC.SQLServer qualified as Sqlserver
|
|
import GHC.Stack
|
|
import Harness.Constants as Constants
|
|
import System.Process.Typed
|
|
import Prelude
|
|
|
|
-- | Check that the SQLServer service is live and ready to accept connections.
|
|
livenessCheck :: HasCallStack => IO ()
|
|
livenessCheck = loop Constants.sqlserverLivenessCheckAttempts
|
|
where
|
|
loop 0 = error ("Liveness check failed for SQLServer.")
|
|
loop attempts =
|
|
catch
|
|
( bracket
|
|
(Sqlserver.connect Constants.sqlserverConnectInfo)
|
|
Sqlserver.close
|
|
(const (pure ()))
|
|
)
|
|
( \(_failure :: ExitCodeException) -> do
|
|
threadDelay
|
|
Constants.sqlserverLivenessCheckIntervalMicroseconds
|
|
loop (attempts - 1)
|
|
)
|
|
|
|
-- | Run a plain SQL string against the server, ignore the
|
|
-- result. Just checks for errors.
|
|
run_ :: HasCallStack => String -> IO ()
|
|
run_ query' =
|
|
catch
|
|
( bracket
|
|
(Sqlserver.connect Constants.sqlserverConnectInfo)
|
|
Sqlserver.close
|
|
(\conn -> void (Sqlserver.exec conn (fromString query')))
|
|
)
|
|
( \(e :: SomeException) ->
|
|
error
|
|
( unlines
|
|
[ "SQLServer query error:",
|
|
show e,
|
|
"SQL was:",
|
|
query'
|
|
]
|
|
)
|
|
)
|