2020-04-24 10:55:51 +03:00
|
|
|
-- | The RQL query ('/v1/query')
|
2019-12-09 01:17:39 +03:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
2020-04-24 10:55:51 +03:00
|
|
|
|
|
|
|
module Hasura.Server.API.Query where
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2019-10-18 11:29:47 +03:00
|
|
|
import Control.Lens
|
2018-06-27 16:11:32 +03:00
|
|
|
import Data.Aeson
|
|
|
|
import Data.Aeson.Casing
|
|
|
|
import Data.Aeson.TH
|
2019-03-12 08:46:27 +03:00
|
|
|
import Data.Time (UTCTime)
|
2019-03-01 12:17:22 +03:00
|
|
|
import Language.Haskell.TH.Syntax (Lift)
|
2019-09-19 07:47:36 +03:00
|
|
|
|
|
|
|
import qualified Data.HashMap.Strict as HM
|
2019-11-15 03:20:18 +03:00
|
|
|
import qualified Data.Text as T
|
2019-11-26 15:14:21 +03:00
|
|
|
import qualified Database.PG.Query as Q
|
2019-03-01 12:17:22 +03:00
|
|
|
import qualified Network.HTTP.Client as HTTP
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2019-03-18 19:22:21 +03:00
|
|
|
import Hasura.EncJSON
|
2018-06-27 16:11:32 +03:00
|
|
|
import Hasura.Prelude
|
2020-02-13 20:38:23 +03:00
|
|
|
import Hasura.RQL.DDL.Action
|
2019-10-18 11:29:47 +03:00
|
|
|
import Hasura.RQL.DDL.ComputedField
|
2020-02-13 20:38:23 +03:00
|
|
|
import Hasura.RQL.DDL.CustomTypes
|
2019-04-17 19:29:39 +03:00
|
|
|
import Hasura.RQL.DDL.EventTrigger
|
2018-06-27 16:11:32 +03:00
|
|
|
import Hasura.RQL.DDL.Metadata
|
|
|
|
import Hasura.RQL.DDL.Permission
|
2019-05-16 09:13:25 +03:00
|
|
|
import Hasura.RQL.DDL.QueryCollection
|
2018-06-27 16:11:32 +03:00
|
|
|
import Hasura.RQL.DDL.Relationship
|
2019-03-01 12:17:22 +03:00
|
|
|
import Hasura.RQL.DDL.Relationship.Rename
|
2018-12-13 10:26:15 +03:00
|
|
|
import Hasura.RQL.DDL.RemoteSchema
|
2019-08-14 02:34:37 +03:00
|
|
|
import Hasura.RQL.DDL.Schema
|
2018-12-13 10:26:15 +03:00
|
|
|
import Hasura.RQL.DML.Count
|
|
|
|
import Hasura.RQL.DML.Delete
|
|
|
|
import Hasura.RQL.DML.Insert
|
|
|
|
import Hasura.RQL.DML.Select
|
|
|
|
import Hasura.RQL.DML.Update
|
2018-06-27 16:11:32 +03:00
|
|
|
import Hasura.RQL.Types
|
2019-12-09 01:17:39 +03:00
|
|
|
import Hasura.RQL.Types.Run
|
2019-03-12 08:46:27 +03:00
|
|
|
import Hasura.Server.Init (InstanceId (..))
|
2019-03-01 14:45:04 +03:00
|
|
|
import Hasura.Server.Utils
|
2020-01-23 00:55:55 +03:00
|
|
|
import Hasura.Server.Version (HasVersion)
|
2020-04-24 12:10:53 +03:00
|
|
|
import Hasura.Session
|
2018-06-27 16:11:32 +03:00
|
|
|
|
|
|
|
|
2019-09-19 07:47:36 +03:00
|
|
|
data RQLQueryV1
|
2018-06-27 16:11:32 +03:00
|
|
|
= RQAddExistingTableOrView !TrackTable
|
|
|
|
| RQTrackTable !TrackTable
|
|
|
|
| RQUntrackTable !UntrackTable
|
2019-07-22 15:47:13 +03:00
|
|
|
| RQSetTableIsEnum !SetTableIsEnum
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2019-01-25 06:31:54 +03:00
|
|
|
| RQTrackFunction !TrackFunction
|
|
|
|
| RQUntrackFunction !UnTrackFunction
|
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQCreateObjectRelationship !CreateObjRel
|
|
|
|
| RQCreateArrayRelationship !CreateArrRel
|
|
|
|
| RQDropRelationship !DropRel
|
|
|
|
| RQSetRelationshipComment !SetRelComment
|
2019-03-01 12:17:22 +03:00
|
|
|
| RQRenameRelationship !RenameRel
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2019-10-18 11:29:47 +03:00
|
|
|
-- computed fields related
|
|
|
|
|
|
|
|
| RQAddComputedField !AddComputedField
|
|
|
|
| RQDropComputedField !DropComputedField
|
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQCreateInsertPermission !CreateInsPerm
|
|
|
|
| RQCreateSelectPermission !CreateSelPerm
|
|
|
|
| RQCreateUpdatePermission !CreateUpdPerm
|
|
|
|
| RQCreateDeletePermission !CreateDelPerm
|
|
|
|
|
2020-01-16 07:53:28 +03:00
|
|
|
| RQDropInsertPermission !(DropPerm InsPerm)
|
|
|
|
| RQDropSelectPermission !(DropPerm SelPerm)
|
|
|
|
| RQDropUpdatePermission !(DropPerm UpdPerm)
|
|
|
|
| RQDropDeletePermission !(DropPerm DelPerm)
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQSetPermissionComment !SetPermComment
|
|
|
|
|
2019-04-17 19:29:39 +03:00
|
|
|
| RQGetInconsistentMetadata !GetInconsistentMetadata
|
|
|
|
| RQDropInconsistentMetadata !DropInconsistentMetadata
|
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQInsert !InsertQuery
|
|
|
|
| RQSelect !SelectQuery
|
|
|
|
| RQUpdate !UpdateQuery
|
|
|
|
| RQDelete !DeleteQuery
|
|
|
|
| RQCount !CountQuery
|
|
|
|
| RQBulk ![RQLQuery]
|
|
|
|
|
2018-11-23 16:02:46 +03:00
|
|
|
-- schema-stitching, custom resolver related
|
|
|
|
| RQAddRemoteSchema !AddRemoteSchemaQuery
|
2019-07-08 08:51:41 +03:00
|
|
|
| RQRemoveRemoteSchema !RemoteSchemaNameQuery
|
|
|
|
| RQReloadRemoteSchema !RemoteSchemaNameQuery
|
2018-11-23 16:02:46 +03:00
|
|
|
|
2018-09-05 14:26:46 +03:00
|
|
|
| RQCreateEventTrigger !CreateEventTriggerQuery
|
|
|
|
| RQDeleteEventTrigger !DeleteEventTriggerQuery
|
2019-05-13 12:41:07 +03:00
|
|
|
| RQRedeliverEvent !RedeliverEventQuery
|
|
|
|
| RQInvokeEventTrigger !InvokeEventTriggerQuery
|
2018-09-05 14:26:46 +03:00
|
|
|
|
2019-05-16 09:13:25 +03:00
|
|
|
-- query collections, allow list related
|
|
|
|
| RQCreateQueryCollection !CreateCollection
|
|
|
|
| RQDropQueryCollection !DropCollection
|
|
|
|
| RQAddQueryToCollection !AddQueryToCollection
|
|
|
|
| RQDropQueryFromCollection !DropQueryFromCollection
|
|
|
|
| RQAddCollectionToAllowlist !CollectionReq
|
|
|
|
| RQDropCollectionFromAllowlist !CollectionReq
|
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQRunSql !RunSQL
|
|
|
|
|
|
|
|
| RQReplaceMetadata !ReplaceMetadata
|
|
|
|
| RQExportMetadata !ExportMetadata
|
|
|
|
| RQClearMetadata !ClearMetadata
|
2018-09-05 18:25:30 +03:00
|
|
|
| RQReloadMetadata !ReloadMetadata
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2020-02-13 20:38:23 +03:00
|
|
|
| RQCreateAction !CreateAction
|
|
|
|
| RQDropAction !DropAction
|
|
|
|
| RQUpdateAction !UpdateAction
|
|
|
|
| RQCreateActionPermission !CreateActionPermission
|
|
|
|
| RQDropActionPermission !DropActionPermission
|
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQDumpInternalState !DumpInternalState
|
2020-02-13 20:38:23 +03:00
|
|
|
| RQSetCustomTypes !CustomTypes
|
2018-06-27 16:11:32 +03:00
|
|
|
deriving (Show, Eq, Lift)
|
|
|
|
|
2019-09-19 07:47:36 +03:00
|
|
|
data RQLQueryV2
|
|
|
|
= RQV2TrackTable !TrackTableV2
|
|
|
|
| RQV2SetTableCustomFields !SetTableCustomFields
|
2019-11-20 09:47:06 +03:00
|
|
|
| RQV2TrackFunction !TrackFunctionV2
|
2019-09-19 07:47:36 +03:00
|
|
|
deriving (Show, Eq, Lift)
|
|
|
|
|
|
|
|
data RQLQuery
|
|
|
|
= RQV1 !RQLQueryV1
|
|
|
|
| RQV2 !RQLQueryV2
|
|
|
|
deriving (Show, Eq, Lift)
|
|
|
|
|
|
|
|
instance FromJSON RQLQuery where
|
|
|
|
parseJSON = withObject "Object" $ \o -> do
|
|
|
|
mVersion <- o .:? "version"
|
|
|
|
let version = fromMaybe VIVersion1 mVersion
|
|
|
|
val = Object o
|
|
|
|
case version of
|
|
|
|
VIVersion1 -> RQV1 <$> parseJSON val
|
|
|
|
VIVersion2 -> RQV2 <$> parseJSON val
|
|
|
|
|
|
|
|
instance ToJSON RQLQuery where
|
|
|
|
toJSON = \case
|
|
|
|
RQV1 q -> embedVersion VIVersion1 $ toJSON q
|
|
|
|
RQV2 q -> embedVersion VIVersion2 $ toJSON q
|
|
|
|
where
|
|
|
|
embedVersion version (Object o) =
|
|
|
|
Object $ HM.insert "version" (toJSON version) o
|
|
|
|
-- never happens since JSON value of RQL queries are always objects
|
|
|
|
embedVersion _ _ = error "Unexpected: toJSON of RQL queries are not objects"
|
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
$(deriveJSON
|
|
|
|
defaultOptions { constructorTagModifier = snakeCase . drop 2
|
|
|
|
, sumEncoding = TaggedObject "type" "args"
|
|
|
|
}
|
2019-09-19 07:47:36 +03:00
|
|
|
''RQLQueryV1)
|
|
|
|
|
|
|
|
$(deriveJSON
|
|
|
|
defaultOptions { constructorTagModifier = snakeCase . drop 4
|
|
|
|
, sumEncoding = TaggedObject "type" "args"
|
|
|
|
, tagSingleConstructors = True
|
|
|
|
}
|
|
|
|
''RQLQueryV2
|
|
|
|
)
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2020-01-30 02:03:49 +03:00
|
|
|
fetchLastUpdate :: Q.TxE QErr (Maybe (InstanceId, UTCTime, CacheInvalidations))
|
|
|
|
fetchLastUpdate = over (_Just._3) Q.getAltJ <$> Q.withQE defaultTxErrorHandler [Q.sql|
|
|
|
|
SELECT instance_id::text, occurred_at, invalidations
|
|
|
|
FROM hdb_catalog.hdb_schema_update_event
|
|
|
|
ORDER BY occurred_at DESC LIMIT 1
|
|
|
|
|] () True
|
|
|
|
|
|
|
|
recordSchemaUpdate :: InstanceId -> CacheInvalidations -> Q.TxE QErr ()
|
|
|
|
recordSchemaUpdate instanceId invalidations =
|
2019-03-12 08:46:27 +03:00
|
|
|
liftTx $ Q.unitQE defaultTxErrorHandler [Q.sql|
|
2019-07-31 12:01:48 +03:00
|
|
|
INSERT INTO hdb_catalog.hdb_schema_update_event
|
2020-01-30 02:03:49 +03:00
|
|
|
(instance_id, occurred_at, invalidations) VALUES ($1::uuid, DEFAULT, $2::json)
|
2019-07-31 12:01:48 +03:00
|
|
|
ON CONFLICT ((occurred_at IS NOT NULL))
|
2020-01-30 02:03:49 +03:00
|
|
|
DO UPDATE SET instance_id = $1::uuid, occurred_at = DEFAULT, invalidations = $2::json
|
|
|
|
|] (instanceId, Q.AltJ invalidations) True
|
2019-03-12 08:46:27 +03:00
|
|
|
|
2018-06-27 16:11:32 +03:00
|
|
|
runQuery
|
2020-01-23 00:55:55 +03:00
|
|
|
:: (HasVersion, MonadIO m, MonadError QErr m)
|
2019-04-17 12:48:41 +03:00
|
|
|
=> PGExecCtx -> InstanceId
|
2019-11-20 21:21:30 +03:00
|
|
|
-> UserInfo -> RebuildableSchemaCache Run -> HTTP.Manager
|
|
|
|
-> SQLGenCtx -> SystemDefined -> RQLQuery -> m (EncJSON, RebuildableSchemaCache Run)
|
2019-10-11 08:13:57 +03:00
|
|
|
runQuery pgExecCtx instanceId userInfo sc hMgr sqlGenCtx systemDefined query = do
|
2019-11-15 03:20:18 +03:00
|
|
|
accessMode <- getQueryAccessMode query
|
2019-10-21 19:01:05 +03:00
|
|
|
resE <- runQueryM query
|
|
|
|
& runHasSystemDefinedT systemDefined
|
2019-11-20 21:21:30 +03:00
|
|
|
& runCacheRWT sc
|
|
|
|
& peelRun runCtx pgExecCtx accessMode
|
2019-10-21 19:01:05 +03:00
|
|
|
& runExceptT
|
|
|
|
& liftIO
|
2019-03-12 08:46:27 +03:00
|
|
|
either throwError withReload resE
|
|
|
|
where
|
2019-10-21 19:01:05 +03:00
|
|
|
runCtx = RunCtx userInfo hMgr sqlGenCtx
|
2020-01-30 02:03:49 +03:00
|
|
|
withReload (result, updatedCache, invalidations) = do
|
2020-01-09 02:19:02 +03:00
|
|
|
when (queryModifiesSchemaCache query) $ do
|
2020-01-30 02:03:49 +03:00
|
|
|
e <- liftIO $ runExceptT $ runLazyTx pgExecCtx Q.ReadWrite $ liftTx $
|
|
|
|
recordSchemaUpdate instanceId invalidations
|
2019-03-12 08:46:27 +03:00
|
|
|
liftEither e
|
2020-01-30 02:03:49 +03:00
|
|
|
return (result, updatedCache)
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2020-01-09 02:19:02 +03:00
|
|
|
-- | A predicate that determines whether the given query might modify/rebuild the schema cache. If
|
|
|
|
-- so, it needs to acquire the global lock on the schema cache so that other queries do not modify
|
|
|
|
-- it concurrently.
|
|
|
|
--
|
|
|
|
-- Ideally, we would enforce this using the type system — queries for which this function returns
|
|
|
|
-- 'False' should not be allowed to modify the schema cache. But for now we just ensure consistency
|
|
|
|
-- by hand.
|
|
|
|
queryModifiesSchemaCache :: RQLQuery -> Bool
|
|
|
|
queryModifiesSchemaCache (RQV1 qi) = case qi of
|
2019-05-16 09:13:25 +03:00
|
|
|
RQAddExistingTableOrView _ -> True
|
|
|
|
RQTrackTable _ -> True
|
|
|
|
RQUntrackTable _ -> True
|
|
|
|
RQTrackFunction _ -> True
|
|
|
|
RQUntrackFunction _ -> True
|
2019-07-22 15:47:13 +03:00
|
|
|
RQSetTableIsEnum _ -> True
|
2019-05-16 09:13:25 +03:00
|
|
|
|
|
|
|
RQCreateObjectRelationship _ -> True
|
|
|
|
RQCreateArrayRelationship _ -> True
|
|
|
|
RQDropRelationship _ -> True
|
|
|
|
RQSetRelationshipComment _ -> False
|
|
|
|
RQRenameRelationship _ -> True
|
|
|
|
|
2019-10-18 11:29:47 +03:00
|
|
|
RQAddComputedField _ -> True
|
|
|
|
RQDropComputedField _ -> True
|
|
|
|
|
2019-05-16 09:13:25 +03:00
|
|
|
RQCreateInsertPermission _ -> True
|
|
|
|
RQCreateSelectPermission _ -> True
|
|
|
|
RQCreateUpdatePermission _ -> True
|
|
|
|
RQCreateDeletePermission _ -> True
|
|
|
|
|
|
|
|
RQDropInsertPermission _ -> True
|
|
|
|
RQDropSelectPermission _ -> True
|
|
|
|
RQDropUpdatePermission _ -> True
|
|
|
|
RQDropDeletePermission _ -> True
|
|
|
|
RQSetPermissionComment _ -> False
|
|
|
|
|
|
|
|
RQGetInconsistentMetadata _ -> False
|
|
|
|
RQDropInconsistentMetadata _ -> True
|
|
|
|
|
|
|
|
RQInsert _ -> False
|
|
|
|
RQSelect _ -> False
|
|
|
|
RQUpdate _ -> False
|
|
|
|
RQDelete _ -> False
|
|
|
|
RQCount _ -> False
|
|
|
|
|
|
|
|
RQAddRemoteSchema _ -> True
|
|
|
|
RQRemoveRemoteSchema _ -> True
|
2019-07-08 08:51:41 +03:00
|
|
|
RQReloadRemoteSchema _ -> True
|
2019-05-16 09:13:25 +03:00
|
|
|
|
|
|
|
RQCreateEventTrigger _ -> True
|
|
|
|
RQDeleteEventTrigger _ -> True
|
|
|
|
RQRedeliverEvent _ -> False
|
|
|
|
RQInvokeEventTrigger _ -> False
|
|
|
|
|
|
|
|
RQCreateQueryCollection _ -> True
|
|
|
|
RQDropQueryCollection _ -> True
|
|
|
|
RQAddQueryToCollection _ -> True
|
|
|
|
RQDropQueryFromCollection _ -> True
|
|
|
|
RQAddCollectionToAllowlist _ -> True
|
|
|
|
RQDropCollectionFromAllowlist _ -> True
|
|
|
|
|
2020-04-23 00:03:23 +03:00
|
|
|
RQRunSql q -> isSchemaCacheBuildRequiredRunSQL q
|
2019-05-16 09:13:25 +03:00
|
|
|
|
|
|
|
RQReplaceMetadata _ -> True
|
|
|
|
RQExportMetadata _ -> False
|
|
|
|
RQClearMetadata _ -> True
|
|
|
|
RQReloadMetadata _ -> True
|
|
|
|
|
2020-02-13 20:38:23 +03:00
|
|
|
RQCreateAction _ -> True
|
|
|
|
RQDropAction _ -> True
|
|
|
|
RQUpdateAction _ -> True
|
|
|
|
RQCreateActionPermission _ -> True
|
|
|
|
RQDropActionPermission _ -> True
|
|
|
|
|
2019-05-16 09:13:25 +03:00
|
|
|
RQDumpInternalState _ -> False
|
2020-02-13 20:38:23 +03:00
|
|
|
RQSetCustomTypes _ -> True
|
2019-05-16 09:13:25 +03:00
|
|
|
|
2020-01-09 02:19:02 +03:00
|
|
|
RQBulk qs -> any queryModifiesSchemaCache qs
|
|
|
|
queryModifiesSchemaCache (RQV2 qi) = case qi of
|
2019-09-19 07:47:36 +03:00
|
|
|
RQV2TrackTable _ -> True
|
|
|
|
RQV2SetTableCustomFields _ -> True
|
2019-11-20 09:47:06 +03:00
|
|
|
RQV2TrackFunction _ -> True
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2019-11-15 03:20:18 +03:00
|
|
|
getQueryAccessMode :: (MonadError QErr m) => RQLQuery -> m Q.TxAccess
|
2019-12-04 22:16:37 +03:00
|
|
|
getQueryAccessMode q = (fromMaybe Q.ReadOnly) <$> getQueryAccessMode' q
|
2019-11-15 03:20:18 +03:00
|
|
|
where
|
2019-12-04 22:16:37 +03:00
|
|
|
getQueryAccessMode' ::
|
|
|
|
(MonadError QErr m) => RQLQuery -> m (Maybe Q.TxAccess)
|
|
|
|
getQueryAccessMode' (RQV1 q') =
|
|
|
|
case q' of
|
|
|
|
RQSelect _ -> pure Nothing
|
|
|
|
RQCount _ -> pure Nothing
|
|
|
|
RQRunSql RunSQL {rTxAccessMode} -> pure $ Just rTxAccessMode
|
|
|
|
RQBulk qs -> foldM reconcileAccessModeWith Nothing (zip [0 :: Integer ..] qs)
|
|
|
|
_ -> pure $ Just Q.ReadWrite
|
|
|
|
where
|
|
|
|
reconcileAccessModeWith expectedMode (i, query) = do
|
|
|
|
queryMode <- getQueryAccessMode' query
|
|
|
|
onLeft (reconcileAccessModes expectedMode queryMode) $ \errMode ->
|
|
|
|
throw400 BadRequest $
|
|
|
|
"incompatible access mode requirements in bulk query, " <>
|
|
|
|
"expected access mode: " <>
|
|
|
|
(T.pack $ maybe "ANY" show expectedMode) <>
|
|
|
|
" but " <>
|
|
|
|
"$.args[" <>
|
|
|
|
(T.pack $ show i) <>
|
|
|
|
"] forces " <>
|
|
|
|
(T.pack $ show errMode)
|
|
|
|
getQueryAccessMode' (RQV2 _) = pure $ Just Q.ReadWrite
|
|
|
|
|
|
|
|
-- | onRight, return reconciled access mode. onLeft, return conflicting access mode
|
|
|
|
reconcileAccessModes :: Maybe Q.TxAccess -> Maybe Q.TxAccess -> Either Q.TxAccess (Maybe Q.TxAccess)
|
|
|
|
reconcileAccessModes Nothing mode = pure mode
|
|
|
|
reconcileAccessModes mode Nothing = pure mode
|
|
|
|
reconcileAccessModes (Just mode1) (Just mode2)
|
|
|
|
| mode1 == mode2 = pure $ Just mode1
|
|
|
|
| otherwise = Left mode2
|
2019-11-15 03:20:18 +03:00
|
|
|
|
2018-12-13 10:26:15 +03:00
|
|
|
runQueryM
|
2020-01-23 00:55:55 +03:00
|
|
|
:: ( HasVersion, QErrM m, CacheRWM m, UserInfoM m, MonadTx m
|
2019-03-01 14:45:04 +03:00
|
|
|
, MonadIO m, HasHttpManager m, HasSQLGenCtx m
|
2019-10-11 08:13:57 +03:00
|
|
|
, HasSystemDefined m
|
2018-12-13 10:26:15 +03:00
|
|
|
)
|
|
|
|
=> RQLQuery
|
2019-03-18 19:22:21 +03:00
|
|
|
-> m EncJSON
|
2020-01-09 02:19:02 +03:00
|
|
|
runQueryM rq = withPathK "args" $ case rq of
|
|
|
|
RQV1 q -> runQueryV1M q
|
|
|
|
RQV2 q -> runQueryV2M q
|
2019-07-08 08:51:41 +03:00
|
|
|
where
|
2019-09-19 07:47:36 +03:00
|
|
|
runQueryV1M = \case
|
2019-07-08 08:51:41 +03:00
|
|
|
RQAddExistingTableOrView q -> runTrackTableQ q
|
|
|
|
RQTrackTable q -> runTrackTableQ q
|
|
|
|
RQUntrackTable q -> runUntrackTableQ q
|
2019-07-22 15:47:13 +03:00
|
|
|
RQSetTableIsEnum q -> runSetExistingTableIsEnumQ q
|
2019-07-08 08:51:41 +03:00
|
|
|
|
|
|
|
RQTrackFunction q -> runTrackFunc q
|
|
|
|
RQUntrackFunction q -> runUntrackFunc q
|
|
|
|
|
2019-11-20 21:21:30 +03:00
|
|
|
RQCreateObjectRelationship q -> runCreateRelationship ObjRel q
|
|
|
|
RQCreateArrayRelationship q -> runCreateRelationship ArrRel q
|
2019-07-08 08:51:41 +03:00
|
|
|
RQDropRelationship q -> runDropRel q
|
|
|
|
RQSetRelationshipComment q -> runSetRelComment q
|
|
|
|
RQRenameRelationship q -> runRenameRel q
|
|
|
|
|
2019-10-18 11:29:47 +03:00
|
|
|
RQAddComputedField q -> runAddComputedField q
|
|
|
|
RQDropComputedField q -> runDropComputedField q
|
|
|
|
|
2019-07-08 08:51:41 +03:00
|
|
|
RQCreateInsertPermission q -> runCreatePerm q
|
|
|
|
RQCreateSelectPermission q -> runCreatePerm q
|
|
|
|
RQCreateUpdatePermission q -> runCreatePerm q
|
|
|
|
RQCreateDeletePermission q -> runCreatePerm q
|
|
|
|
|
|
|
|
RQDropInsertPermission q -> runDropPerm q
|
|
|
|
RQDropSelectPermission q -> runDropPerm q
|
|
|
|
RQDropUpdatePermission q -> runDropPerm q
|
|
|
|
RQDropDeletePermission q -> runDropPerm q
|
|
|
|
RQSetPermissionComment q -> runSetPermComment q
|
|
|
|
|
|
|
|
RQGetInconsistentMetadata q -> runGetInconsistentMetadata q
|
|
|
|
RQDropInconsistentMetadata q -> runDropInconsistentMetadata q
|
|
|
|
|
|
|
|
RQInsert q -> runInsert q
|
|
|
|
RQSelect q -> runSelect q
|
|
|
|
RQUpdate q -> runUpdate q
|
|
|
|
RQDelete q -> runDelete q
|
|
|
|
RQCount q -> runCount q
|
|
|
|
|
|
|
|
RQAddRemoteSchema q -> runAddRemoteSchema q
|
|
|
|
RQRemoveRemoteSchema q -> runRemoveRemoteSchema q
|
|
|
|
RQReloadRemoteSchema q -> runReloadRemoteSchema q
|
|
|
|
|
|
|
|
RQCreateEventTrigger q -> runCreateEventTriggerQuery q
|
|
|
|
RQDeleteEventTrigger q -> runDeleteEventTriggerQuery q
|
|
|
|
RQRedeliverEvent q -> runRedeliverEvent q
|
|
|
|
RQInvokeEventTrigger q -> runInvokeEventTrigger q
|
|
|
|
|
|
|
|
RQCreateQueryCollection q -> runCreateCollection q
|
|
|
|
RQDropQueryCollection q -> runDropCollection q
|
|
|
|
RQAddQueryToCollection q -> runAddQueryToCollection q
|
|
|
|
RQDropQueryFromCollection q -> runDropQueryFromCollection q
|
|
|
|
RQAddCollectionToAllowlist q -> runAddCollectionToAllowlist q
|
|
|
|
RQDropCollectionFromAllowlist q -> runDropCollectionFromAllowlist q
|
|
|
|
|
|
|
|
RQReplaceMetadata q -> runReplaceMetadata q
|
|
|
|
RQClearMetadata q -> runClearMetadata q
|
|
|
|
RQExportMetadata q -> runExportMetadata q
|
|
|
|
RQReloadMetadata q -> runReloadMetadata q
|
|
|
|
|
2020-02-13 20:38:23 +03:00
|
|
|
RQCreateAction q -> runCreateAction q
|
|
|
|
RQDropAction q -> runDropAction q
|
|
|
|
RQUpdateAction q -> runUpdateAction q
|
|
|
|
RQCreateActionPermission q -> runCreateActionPermission q
|
|
|
|
RQDropActionPermission q -> runDropActionPermission q
|
|
|
|
|
2019-07-08 08:51:41 +03:00
|
|
|
RQDumpInternalState q -> runDumpInternalState q
|
|
|
|
|
|
|
|
RQRunSql q -> runRunSQL q
|
|
|
|
|
2020-02-13 20:38:23 +03:00
|
|
|
RQSetCustomTypes q -> runSetCustomTypes q
|
|
|
|
|
2019-07-08 08:51:41 +03:00
|
|
|
RQBulk qs -> encJFromList <$> indexedMapM runQueryM qs
|
2019-09-19 07:47:36 +03:00
|
|
|
|
|
|
|
runQueryV2M = \case
|
|
|
|
RQV2TrackTable q -> runTrackTableV2Q q
|
|
|
|
RQV2SetTableCustomFields q -> runSetTableCustomFieldsQV2 q
|
2019-11-20 09:47:06 +03:00
|
|
|
RQV2TrackFunction q -> runTrackFunctionV2 q
|
2019-11-26 15:14:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
requiresAdmin :: RQLQuery -> Bool
|
|
|
|
requiresAdmin = \case
|
|
|
|
RQV1 q -> case q of
|
|
|
|
RQAddExistingTableOrView _ -> True
|
|
|
|
RQTrackTable _ -> True
|
|
|
|
RQUntrackTable _ -> True
|
|
|
|
RQSetTableIsEnum _ -> True
|
|
|
|
|
|
|
|
RQTrackFunction _ -> True
|
|
|
|
RQUntrackFunction _ -> True
|
|
|
|
|
|
|
|
RQCreateObjectRelationship _ -> True
|
|
|
|
RQCreateArrayRelationship _ -> True
|
|
|
|
RQDropRelationship _ -> True
|
|
|
|
RQSetRelationshipComment _ -> True
|
|
|
|
RQRenameRelationship _ -> True
|
|
|
|
|
|
|
|
RQAddComputedField _ -> True
|
|
|
|
RQDropComputedField _ -> True
|
|
|
|
|
|
|
|
RQCreateInsertPermission _ -> True
|
|
|
|
RQCreateSelectPermission _ -> True
|
|
|
|
RQCreateUpdatePermission _ -> True
|
|
|
|
RQCreateDeletePermission _ -> True
|
|
|
|
|
|
|
|
RQDropInsertPermission _ -> True
|
|
|
|
RQDropSelectPermission _ -> True
|
|
|
|
RQDropUpdatePermission _ -> True
|
|
|
|
RQDropDeletePermission _ -> True
|
|
|
|
RQSetPermissionComment _ -> True
|
|
|
|
|
|
|
|
RQGetInconsistentMetadata _ -> True
|
|
|
|
RQDropInconsistentMetadata _ -> True
|
|
|
|
|
|
|
|
RQInsert _ -> False
|
|
|
|
RQSelect _ -> False
|
|
|
|
RQUpdate _ -> False
|
|
|
|
RQDelete _ -> False
|
|
|
|
RQCount _ -> False
|
|
|
|
|
|
|
|
RQAddRemoteSchema _ -> True
|
|
|
|
RQRemoveRemoteSchema _ -> True
|
|
|
|
RQReloadRemoteSchema _ -> True
|
|
|
|
|
|
|
|
RQCreateEventTrigger _ -> True
|
|
|
|
RQDeleteEventTrigger _ -> True
|
|
|
|
RQRedeliverEvent _ -> True
|
|
|
|
RQInvokeEventTrigger _ -> True
|
|
|
|
|
|
|
|
RQCreateQueryCollection _ -> True
|
|
|
|
RQDropQueryCollection _ -> True
|
|
|
|
RQAddQueryToCollection _ -> True
|
|
|
|
RQDropQueryFromCollection _ -> True
|
|
|
|
RQAddCollectionToAllowlist _ -> True
|
|
|
|
RQDropCollectionFromAllowlist _ -> True
|
|
|
|
|
|
|
|
RQReplaceMetadata _ -> True
|
|
|
|
RQClearMetadata _ -> True
|
|
|
|
RQExportMetadata _ -> True
|
|
|
|
RQReloadMetadata _ -> True
|
|
|
|
|
2020-02-13 20:38:23 +03:00
|
|
|
RQCreateAction _ -> True
|
|
|
|
RQDropAction _ -> True
|
|
|
|
RQUpdateAction _ -> True
|
|
|
|
RQCreateActionPermission _ -> True
|
|
|
|
RQDropActionPermission _ -> True
|
|
|
|
|
2019-11-26 15:14:21 +03:00
|
|
|
RQDumpInternalState _ -> True
|
2020-02-13 20:38:23 +03:00
|
|
|
RQSetCustomTypes _ -> True
|
2019-11-26 15:14:21 +03:00
|
|
|
|
|
|
|
RQRunSql _ -> True
|
|
|
|
|
|
|
|
RQBulk qs -> any requiresAdmin qs
|
|
|
|
|
|
|
|
RQV2 q -> case q of
|
|
|
|
RQV2TrackTable _ -> True
|
|
|
|
RQV2SetTableCustomFields _ -> True
|
|
|
|
RQV2TrackFunction _ -> True
|