mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
Allow running read-only run_sql queries in read-only mode
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8409 GitOrigin-RevId: f7e92c0ba03d5b2b1d6a9d8060a49b351c56bd52
This commit is contained in:
parent
e6da837dbf
commit
c8c0fd200f
@ -14,6 +14,7 @@
|
||||
module Hasura.Backends.Postgres.DDL.RunSQL
|
||||
( runRunSQL,
|
||||
RunSQL (..),
|
||||
isReadOnly,
|
||||
isSchemaCacheBuildRequiredRunSQL,
|
||||
)
|
||||
where
|
||||
@ -80,8 +81,8 @@ instance FromJSON RunSQL where
|
||||
rSource <- o .:? "source" .!= defaultSource
|
||||
rCascade <- o .:? "cascade" .!= False
|
||||
rCheckMetadataConsistency <- o .:? "check_metadata_consistency"
|
||||
isReadOnly <- o .:? "read_only" .!= False
|
||||
let rTxAccessMode = if isReadOnly then PG.ReadOnly else PG.ReadWrite
|
||||
readOnly <- o .:? "read_only" .!= False
|
||||
let rTxAccessMode = if readOnly then PG.ReadOnly else PG.ReadWrite
|
||||
pure RunSQL {..}
|
||||
|
||||
instance ToJSON RunSQL where
|
||||
@ -120,6 +121,12 @@ isSchemaCacheBuildRequiredRunSQL RunSQL {..} =
|
||||
"\\balter\\b|\\bdrop\\b|\\breplace\\b|\\bcreate function\\b|\\bcomment on\\b"
|
||||
)
|
||||
|
||||
isReadOnly :: RunSQL -> Bool
|
||||
isReadOnly runsql =
|
||||
case rTxAccessMode runsql of
|
||||
PG.ReadOnly -> True
|
||||
PG.ReadWrite -> False
|
||||
|
||||
{- Note [Checking metadata consistency in run_sql]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
SQL queries executed by run_sql may change the Postgres schema in arbitrary
|
||||
|
@ -204,9 +204,9 @@ queryModifiesUserDB = \case
|
||||
RQUpdate _ -> True
|
||||
RQDelete _ -> True
|
||||
RQCount _ -> False
|
||||
RQRunSql _ -> True
|
||||
RQCitusRunSql _ -> True
|
||||
RQCockroachRunSql _ -> True
|
||||
RQRunSql runsql -> not (Postgres.isReadOnly runsql)
|
||||
RQCitusRunSql runsql -> not (Postgres.isReadOnly runsql)
|
||||
RQCockroachRunSql runsql -> not (Postgres.isReadOnly runsql)
|
||||
RQMssqlRunSql _ -> True
|
||||
RQMysqlRunSql _ -> True
|
||||
RQBigqueryRunSql _ -> True
|
||||
|
Loading…
Reference in New Issue
Block a user