graphql-engine/server/tests-py/queries/graphql_mutation/delete/permissions/schema_setup.yaml

133 lines
2.4 KiB
YAML

type: bulk
args:
#Author table
- type: run_sql
args:
sql: |
create table author(
id serial primary key,
name text unique,
payments_done boolean not null default false
);
- type: track_table
args:
schema: public
name: author
#Article table
- type: run_sql
args:
sql: |
CREATE TABLE article (
id SERIAL PRIMARY KEY,
title TEXT,
content TEXT,
author_id INTEGER NOT NULL REFERENCES author(id),
is_published BOOLEAN,
published_on TIMESTAMP
)
- type: track_table
args:
schema: public
name: article
#Object relationship
- type: create_object_relationship
args:
table: article
name: author
using:
foreign_key_constraint_on: author_id
#Array relationship
- type: create_array_relationship
args:
table: author
name: articles
using:
foreign_key_constraint_on:
table: article
column: author_id
#Prevent deletion if payments to the author is not yet done
- type: create_delete_permission
args:
table: author
role: user
permission:
filter:
$and:
- id: X-HASURA-USER-ID
- payments_done: true
#A user can delete only his articles
- type: create_select_permission
args:
table: article
role: user
permission:
columns:
- id
- title
- content
- author_id
filter:
$and:
- author_id: X-HASURA-USER-ID
#A user can delete only his articles
- type: create_delete_permission
args:
table: article
role: user
permission:
filter:
$and:
- author_id: X-HASURA-USER-ID
#Create resident table
- type: run_sql
args:
sql: |
CREATE TABLE resident (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER NOT NULL
)
- type: track_table
args:
schema: public
name: resident
- type: create_delete_permission
args:
table: resident
role: resident
permission:
filter:
id: X-Hasura-Resident-Id
- type: create_delete_permission
args:
table: resident
role: agent
permission:
filter:
id:
$in: X-Hasura-Allowed-Resident-Ids
- type: create_select_permission
args:
table: resident
role: agent
permission:
columns:
- id
- name
- age
filter:
id:
$in: X-Hasura-Allowed-Resident-Ids