mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-20 06:58:39 +03:00
server: fix create event trigger failure on tables with MSSQL reserved keywords as name
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4648 GitOrigin-RevId: 5e3eb614350b047f2e2384fea9b234bf0ad9d47f
This commit is contained in:
parent
b4534c1177
commit
2526dd0114
@ -172,6 +172,7 @@ is `graphql-default`, the field names generated will be `my_table`, `my_tableByP
|
||||
|
||||
### Bug fixes and improvements
|
||||
|
||||
- server: fix create event trigger failure for MSSQL sources on a table with a table name that is a reserved MSSQL keyword.
|
||||
- server: errors from `/healthz` endpoint are now logged with more details
|
||||
- server: do not expand environment variable references in logs or API responses from remote schemas, actions and event triggers for security reasons
|
||||
- server: introduce [backend_only permissions](https://hasura.io/docs/latest/graphql/core/auth/authorization/permission-rules/#backend-only-permissions) for update and delete mutations (fix #5275)
|
||||
|
@ -34,6 +34,7 @@ import Database.ODBC.TH qualified as ODBC
|
||||
import Hasura.Backends.MSSQL.Connection
|
||||
import Hasura.Backends.MSSQL.DDL.Source.Version
|
||||
import Hasura.Backends.MSSQL.SQL.Error qualified as HGE
|
||||
import Hasura.Backends.MSSQL.ToQuery (fromTableName, toQueryFlat)
|
||||
import Hasura.Backends.MSSQL.Types (SchemaName (..), TableName (..))
|
||||
import Hasura.Backends.MSSQL.Types.Internal (columnNameText, geoTypes)
|
||||
import Hasura.Base.Error
|
||||
@ -633,11 +634,10 @@ generateColumnTriggerAlias op colPrefixMaybe colInfo =
|
||||
-- If no colPrefixMaybe was Nothing then alias will be 'id as payload.data.old.id`
|
||||
SQLFragment $ LT.toStrict $ [ST.stext| #{joinPrefixedDbColNameText} as [#{dbColAlias}]|]
|
||||
|
||||
-- Converts tables name to the format [SCHEMA].[TABLENAME]
|
||||
-- eg: [dbo].[author], [hge].[books]
|
||||
qualifyTableName :: TableName -> Text
|
||||
qualifyTableName (TableName tableName (SchemaName schemaName)) =
|
||||
if schemaName == "dbo"
|
||||
then tableName
|
||||
else schemaName <> "." <> tableName
|
||||
qualifyTableName = toTxt . toQueryFlat . fromTableName
|
||||
|
||||
mkInsertTriggerQuery :: TableName -> TriggerName -> [ColumnInfo 'MSSQL] -> LT.Text
|
||||
mkInsertTriggerQuery table@(TableName tableName schema@(SchemaName schemaName)) triggerName columns =
|
||||
|
@ -23,6 +23,7 @@ module Hasura.Backends.MSSQL.ToQuery
|
||||
fromInsertValuesIntoTempTable,
|
||||
dropTempTableQuery,
|
||||
fromRawUnescapedText,
|
||||
fromTableName,
|
||||
(<+>),
|
||||
Printer (..),
|
||||
)
|
||||
|
@ -22,4 +22,33 @@
|
||||
- type: mssql_delete_event_trigger
|
||||
args:
|
||||
source: mssql
|
||||
name: t1_1
|
||||
name: t1_1
|
||||
|
||||
# Should successfully create event triggers on table names which are reserved MSSQL key words.
|
||||
# In this test, we create a table with name "User" which is a reserved MSSQL keyword.
|
||||
# Ref: https://github.com/hasura/graphql-engine/issues/8557
|
||||
- description: create and then drop an event trigger, for a table whose name is a reserved MSSQL keyword
|
||||
url: /v1/metadata
|
||||
status: 200
|
||||
query:
|
||||
type: bulk
|
||||
args:
|
||||
- type: mssql_create_event_trigger
|
||||
args: &def_args1
|
||||
source: mssql
|
||||
name: t1_2
|
||||
table:
|
||||
schema: hge_tests
|
||||
name: User
|
||||
insert:
|
||||
columns: "*"
|
||||
update:
|
||||
columns: "*"
|
||||
delete:
|
||||
columns: "*"
|
||||
webhook: http://127.0.0.1:5592
|
||||
|
||||
- type: mssql_delete_event_trigger
|
||||
args:
|
||||
source: mssql
|
||||
name: t1_2
|
||||
|
@ -10,3 +10,12 @@ args:
|
||||
c1 int PRIMARY KEY,
|
||||
c2 NVARCHAR(MAX)
|
||||
);
|
||||
|
||||
- type: mssql_run_sql
|
||||
args:
|
||||
source: mssql
|
||||
sql: |
|
||||
create table [hge_tests].[User](
|
||||
c1 int PRIMARY KEY,
|
||||
c2 NVARCHAR(MAX)
|
||||
);
|
||||
|
@ -6,4 +6,5 @@ args:
|
||||
source: mssql
|
||||
sql: |
|
||||
drop table hge_tests.test_t1
|
||||
drop schema hge_tests
|
||||
drop table [hge_tests].[User]
|
||||
drop schema hge_tests
|
||||
|
@ -6,4 +6,11 @@ args:
|
||||
source: mssql
|
||||
table:
|
||||
schema: hge_tests
|
||||
name: test_t1
|
||||
name: test_t1
|
||||
|
||||
- type: mssql_track_table
|
||||
args:
|
||||
source: mssql
|
||||
table:
|
||||
schema: hge_tests
|
||||
name: User
|
||||
|
Loading…
Reference in New Issue
Block a user