mirror of
https://github.com/zhigang1992/graphql-engine.git
synced 2026-05-24 17:03:37 +08:00
committed by
Vamshi Surabhi
parent
ea19bef9b6
commit
dc84bb4e77
@@ -133,10 +133,13 @@ buildInsPermInfo tabInfo (PermDef rn (InsPerm chk set mCols) _) =
|
||||
(be, beDeps) <- withPathK "check" $
|
||||
-- procBoolExp tn fieldInfoMap (S.QualVar "NEW") chk
|
||||
procBoolExp tn fieldInfoMap chk
|
||||
let fltrHeaders = getDependentHeaders chk
|
||||
(setColsSQL, setHdrs, setColDeps) <- procSetObj tabInfo set
|
||||
let reqHdrs = fltrHeaders `union` setHdrs
|
||||
deps = mkParentDep tn : beDeps ++ setColDeps
|
||||
void $ withPathK "columns" $ indexedForM insCols $ \col ->
|
||||
askPGType fieldInfoMap col ""
|
||||
let fltrHeaders = getDependentHeaders chk
|
||||
reqHdrs = fltrHeaders `union` setHdrs
|
||||
insColDeps = map (mkColDep "untyped" tn) insCols
|
||||
deps = mkParentDep tn : beDeps ++ setColDeps ++ insColDeps
|
||||
insColsWithoutPresets = insCols \\ HM.keys setColsSQL
|
||||
return (InsPermInfo (HS.fromList insColsWithoutPresets) vn be setColsSQL reqHdrs, deps)
|
||||
where
|
||||
@@ -285,7 +288,7 @@ buildUpdPermInfo tabInfo (UpdPerm colSpec set fltr) = do
|
||||
(setColsSQL, setHeaders, setColDeps) <- procSetObj tabInfo set
|
||||
|
||||
-- check if the columns exist
|
||||
_ <- withPathK "columns" $ indexedForM updCols $ \updCol ->
|
||||
void $ withPathK "columns" $ indexedForM updCols $ \updCol ->
|
||||
askPGType fieldInfoMap updCol relInUpdErr
|
||||
|
||||
let updColDeps = map (mkColDep "untyped" tn) updCols
|
||||
|
||||
@@ -6,7 +6,7 @@ args:
|
||||
args:
|
||||
sql: |
|
||||
create table author(
|
||||
id serial primary key,
|
||||
id serial primary key,
|
||||
name text unique
|
||||
);
|
||||
insert into author (name) values ('Author 1'), ('Author 2');
|
||||
@@ -20,7 +20,7 @@ args:
|
||||
('article 1 by author 1', 'content for article 1', 1),
|
||||
('article 2 by author 1', 'content for article 2', 1),
|
||||
('article 1 by author 2', 'content for article 3', 2);
|
||||
|
||||
|
||||
- type: track_table
|
||||
args:
|
||||
schema: public
|
||||
@@ -71,3 +71,16 @@ args:
|
||||
permission:
|
||||
check:
|
||||
author_id: X-Hasura-User-Id
|
||||
|
||||
#Article insert permission for user2
|
||||
- type: create_insert_permission
|
||||
args:
|
||||
table: article
|
||||
role: user2
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- title
|
||||
- content
|
||||
- author_id
|
||||
check: {}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#Rename columns
|
||||
- url: /v1/query
|
||||
status: 200
|
||||
query:
|
||||
type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
alter table article rename column title to article_title;
|
||||
|
||||
#Select Queries
|
||||
- url: /v1/query
|
||||
status: 200
|
||||
response:
|
||||
- id: 1
|
||||
article_title: article 1 by author 1
|
||||
content: content for article 1
|
||||
author_id: 1
|
||||
- id: 2
|
||||
article_title: article 2 by author 1
|
||||
content: content for article 2
|
||||
author_id: 1
|
||||
- id: 3
|
||||
article_title: article 1 by author 2
|
||||
content: content for article 3
|
||||
author_id: 2
|
||||
query:
|
||||
type: select
|
||||
args:
|
||||
table: article
|
||||
columns:
|
||||
- id
|
||||
- article_title
|
||||
- content
|
||||
- author_id
|
||||
|
||||
#Revert change
|
||||
- url: /v1/query
|
||||
status: 200
|
||||
query:
|
||||
type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
alter table article rename column article_title to title;
|
||||
|
||||
#Query post revert
|
||||
- url: /v1/query
|
||||
status: 200
|
||||
response:
|
||||
- id: 1
|
||||
title: article 1 by author 1
|
||||
content: content for article 1
|
||||
author_id: 1
|
||||
- id: 2
|
||||
title: article 2 by author 1
|
||||
content: content for article 2
|
||||
author_id: 1
|
||||
- id: 3
|
||||
title: article 1 by author 2
|
||||
content: content for article 3
|
||||
author_id: 2
|
||||
query:
|
||||
type: select
|
||||
args:
|
||||
table: article
|
||||
columns:
|
||||
- id
|
||||
- title
|
||||
- content
|
||||
- author_id
|
||||
@@ -492,8 +492,11 @@ class TestRunSQL(DefaultTestQueries):
|
||||
def test_sql_rename_table(self, hge_ctx):
|
||||
check_query_f(hge_ctx, self.dir() + '/sql_rename_table.yaml')
|
||||
|
||||
def test_sql_rename_columns(self, hge_ctx):
|
||||
check_query_f(hge_ctx, self.dir() + '/sql_rename_columns.yaml')
|
||||
def test_sql_rename_columns_article(self, hge_ctx):
|
||||
check_query_f(hge_ctx, self.dir() + '/sql_rename_columns_article.yaml')
|
||||
|
||||
def test_sql_rename_columns_author(self, hge_ctx):
|
||||
check_query_f(hge_ctx, self.dir() + '/sql_rename_columns_author.yaml')
|
||||
|
||||
def test_sql_rename_table_and_column(self, hge_ctx):
|
||||
check_query_f(hge_ctx, self.dir() + '/sql_rename_table_and_column.yaml')
|
||||
|
||||
Reference in New Issue
Block a user