2018-09-18 09:21:57 +03:00
|
|
|
type: bulk
|
|
|
|
args:
|
|
|
|
|
|
|
|
#Author table
|
2021-01-06 19:06:24 +03:00
|
|
|
|
2018-09-18 09:21:57 +03:00
|
|
|
- type: run_sql
|
|
|
|
args:
|
|
|
|
sql: |
|
|
|
|
create table author(
|
2019-04-08 10:22:38 +03:00
|
|
|
id serial primary key,
|
2018-10-04 15:44:15 +03:00
|
|
|
name text unique,
|
2020-12-02 17:12:06 +03:00
|
|
|
payments_done boolean not null default false,
|
|
|
|
user_id int
|
2018-09-18 09:21:57 +03:00
|
|
|
);
|
|
|
|
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
|
2021-01-06 19:06:24 +03:00
|
|
|
);
|
|
|
|
CREATE TABLE resident (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
age INTEGER NOT NULL
|
|
|
|
);
|
|
|
|
create table "user" (
|
|
|
|
id serial primary key,
|
|
|
|
name text not null unique,
|
|
|
|
is_admin boolean default false
|
|
|
|
);
|
|
|
|
|
|
|
|
create table account (
|
|
|
|
id serial primary key,
|
|
|
|
account_no integer not null
|
|
|
|
);
|
|
|
|
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
schema: public
|
|
|
|
name: author
|
|
|
|
|
|
|
|
#Article table
|
2018-09-18 09:21:57 +03:00
|
|
|
- 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
|
|
|
|
|
2018-10-04 15:44:15 +03:00
|
|
|
#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
|
|
|
|
|
2020-12-02 17:12:06 +03:00
|
|
|
#Author select permission for user
|
|
|
|
- type: create_select_permission
|
|
|
|
args:
|
|
|
|
table: author
|
|
|
|
role: user
|
|
|
|
permission:
|
|
|
|
columns: [id, name, payments_done]
|
|
|
|
filter:
|
|
|
|
id: X-HASURA-USER-ID
|
2018-10-04 15:44:15 +03:00
|
|
|
|
|
|
|
#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
|
2018-10-12 13:36:47 +03:00
|
|
|
|
|
|
|
#Create resident table
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
schema: public
|
|
|
|
name: resident
|
|
|
|
|
|
|
|
- type: create_delete_permission
|
|
|
|
args:
|
|
|
|
table: resident
|
|
|
|
role: resident
|
|
|
|
permission:
|
|
|
|
filter:
|
|
|
|
id: X-Hasura-Resident-Id
|
2019-07-10 13:19:58 +03:00
|
|
|
|
|
|
|
- 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
|
2019-09-05 10:34:53 +03:00
|
|
|
|
|
|
|
# Tables to test '_exist' field
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: user
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: track_table
|
|
|
|
args:
|
|
|
|
name: account
|
|
|
|
schema: public
|
|
|
|
|
|
|
|
- type: create_delete_permission
|
|
|
|
args:
|
|
|
|
table: account
|
|
|
|
role: user
|
|
|
|
permission:
|
|
|
|
filter:
|
|
|
|
_exists:
|
|
|
|
_table: user
|
|
|
|
_where:
|
|
|
|
id: X-Hasura-User-Id
|
|
|
|
is_admin: true
|
|
|
|
|
|
|
|
- type: create_select_permission
|
|
|
|
args:
|
|
|
|
table: account
|
|
|
|
role: user
|
|
|
|
permission:
|
|
|
|
columns:
|
|
|
|
- id
|
|
|
|
- account_no
|
|
|
|
filter:
|
|
|
|
_exists:
|
|
|
|
_table: user
|
|
|
|
_where:
|
|
|
|
id: X-Hasura-User-Id
|
|
|
|
is_admin: true
|