Safe Haskell | None |
---|---|
Language | Haskell2010 |
Postgres DDL RunSQL
Escape hatch for running raw SQL against a postgres database.
runRunSQL
executes the provided raw SQL.
isSchemaCacheBuildRequiredRunSQL
checks for known schema-mutating keywords
in the raw SQL text.
Synopsis
- data RunSQL = RunSQL {
- rSql :: Text
- rSource :: SourceName
- rCascade :: Bool
- rCheckMetadataConsistency :: Maybe Bool
- rTxAccessMode :: TxAccess
- isSchemaCacheBuildRequiredRunSQL :: RunSQL -> Bool
- fetchTablesFunctionsMetadata :: forall pgKind m. (ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, BackendMetadata ('Postgres pgKind), MonadTx m) => TableCache ('Postgres pgKind) -> [TableName ('Postgres pgKind)] -> [FunctionName ('Postgres pgKind)] -> m ([TableMeta ('Postgres pgKind)], [FunctionMeta ('Postgres pgKind)])
- runRunSQL :: forall (pgKind :: PostgresKind) m. (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, HasServerConfigCtx m, MetadataM m, MonadBaseControl IO m, MonadError QErr m, MonadIO m, MonadTrace m, UserInfoM m) => RunSQL -> m EncJSON
- withMetadataCheck :: forall (pgKind :: PostgresKind) a m. (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, HasServerConfigCtx m, MetadataM m, MonadBaseControl IO m, MonadError QErr m, MonadIO m) => SourceName -> Bool -> TxAccess -> TxET QErr m a -> m a
- runTxWithMetadataCheck :: forall m a (pgKind :: PostgresKind). (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, MonadIO m, MonadBaseControl IO m, MonadError QErr m) => SourceName -> SourceConfig ('Postgres pgKind) -> TxAccess -> TableCache ('Postgres pgKind) -> FunctionCache ('Postgres pgKind) -> Bool -> TxET QErr m a -> m (a, MetadataModifier)
- fetchTablesFunctionsFromOids :: MonadIO m => [OID] -> [OID] -> TxET QErr m ([TableName ('Postgres pgKind)], [FunctionName ('Postgres pgKind)])
- getComputedFields :: TableInfo ('Postgres pgKind) -> [ComputedFieldInfo ('Postgres pgKind)]
- getComputedFieldFunctions :: TableInfo ('Postgres pgKind) -> [FunctionName ('Postgres pgKind)]
Documentation
RunSQL | |
|
Instances
Eq RunSQL Source # | |
Show RunSQL Source # | |
FromJSON RunSQL Source # | |
Defined in Hasura.Backends.Postgres.DDL.RunSQL parseJSON :: Value -> Parser RunSQL parseJSONList :: Value -> Parser [RunSQL] | |
ToJSON RunSQL Source # | |
Defined in Hasura.Backends.Postgres.DDL.RunSQL toEncoding :: RunSQL -> Encoding toJSONList :: [RunSQL] -> Value toEncodingList :: [RunSQL] -> Encoding |
isSchemaCacheBuildRequiredRunSQL :: RunSQL -> Bool Source #
Check for known schema-mutating keywords in the raw SQL text.
See Note [Checking metadata consistency in run_sql].
fetchTablesFunctionsMetadata :: forall pgKind m. (ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, BackendMetadata ('Postgres pgKind), MonadTx m) => TableCache ('Postgres pgKind) -> [TableName ('Postgres pgKind)] -> [FunctionName ('Postgres pgKind)] -> m ([TableMeta ('Postgres pgKind)], [FunctionMeta ('Postgres pgKind)]) Source #
Fetch metadata of tracked tablesfunctions and build @TableMeta
FunctionMeta
to calculate diff later in withMetadataCheck
.
runRunSQL :: forall (pgKind :: PostgresKind) m. (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, HasServerConfigCtx m, MetadataM m, MonadBaseControl IO m, MonadError QErr m, MonadIO m, MonadTrace m, UserInfoM m) => RunSQL -> m EncJSON Source #
Used as an escape hatch to run raw SQL against a database.
withMetadataCheck :: forall (pgKind :: PostgresKind) a m. (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, HasServerConfigCtx m, MetadataM m, MonadBaseControl IO m, MonadError QErr m, MonadIO m) => SourceName -> Bool -> TxAccess -> TxET QErr m a -> m a Source #
executes withMetadataCheck
source cascade txAccess runSQLQueryrunSQLQuery
and checks if the schema changed as a
result. If it did, it checks to ensure the changes do not violate any integrity constraints, and
if not, incorporates them into the schema cache.
TODO(antoine): shouldn't this be generalized?
runTxWithMetadataCheck :: forall m a (pgKind :: PostgresKind). (BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind, FetchTableMetadata pgKind, FetchFunctionMetadata pgKind, CacheRWM m, MonadIO m, MonadBaseControl IO m, MonadError QErr m) => SourceName -> SourceConfig ('Postgres pgKind) -> TxAccess -> TableCache ('Postgres pgKind) -> FunctionCache ('Postgres pgKind) -> Bool -> TxET QErr m a -> m (a, MetadataModifier) Source #
'runTxWithMetadataCheck source sourceConfig txAccess tableCache functionCache cascadeDependencies tx' checks for
changes in GraphQL Engine metadata when a
tx
is executed on the database alters Postgres
schema of tables and functions. If any indirect dependencies (Eg. remote table dependence of a relationship) are
found and @cascadeDependencies
is False, then an exception is raised.
fetchTablesFunctionsFromOids :: MonadIO m => [OID] -> [OID] -> TxET QErr m ([TableName ('Postgres pgKind)], [FunctionName ('Postgres pgKind)]) Source #
Fetch list of tables and functions with provided oids
getComputedFields :: TableInfo ('Postgres pgKind) -> [ComputedFieldInfo ('Postgres pgKind)] Source #
getComputedFieldFunctions :: TableInfo ('Postgres pgKind) -> [FunctionName ('Postgres pgKind)] Source #