Skip to content

Commit 07eb2a7

Browse files
committed
Merge branch 'feat/v2'
* feat/v2: (221 commits) small updates add security definer for job triggers token default time tags and comments arrays delete field update field name and type updates updated jobs trigger scheduled jobs rename update hashes build cleanup better hashing better hashing cleanup cleanup transactor ...
2 parents 800c3e7 + 50c3eb7 commit 07eb2a7

File tree

1,314 files changed

+43687
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,314 files changed

+43687
-55
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ env:
2323
- APP_PASSWORD=app_password
2424
matrix:
2525
- PACKAGE=packages/yourpackage1
26-
- PACKAGE=packages/yourpackage2
2726

2827
before_install:
2928
- yarn install
30-
- docker run -p 7777:5432 --name postgres -v `pwd`/packages:/sql-extensions -v `pwd`/node_modules:/sql-modules -d pyramation/postgres-plv8
29+
- docker run -p 7777:5432 --name postgres -v `pwd`/packages:/sql-extensions -d pyramation/postgres
3130
- sleep 3
3231
- while ! docker exec -it postgres pg_isready -U postgres -h 127.0.0.1; do echo "$(date) - waiting for database to start"; sleep 1; done
3332
- while ! docker exec postgres /sql-extensions/install.sh; do echo "installing plugins"; sleep 3; done
3433
- psql -f ./bootstrap-roles.sql postgres
3534
script:
3635
- cd $PACKAGE
3736
- yarn install
38-
- export PGEXTENSIONS=$(cat .env | grep PGEXTENSIONS | awk -F'=' '{print $2}')
3937
- yarn test

Makefile

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
def:
3-
./build.sh skitch plan
4-
./build.sh skitch package --version 0.0.1
3+
./build.sh lql plan
4+
./build.sh lql package --version 0.0.1
55
make install
66

77
up:
@@ -16,19 +16,34 @@ ssh:
1616
install:
1717
$(MAKE) docker-install || $(MAKE) k8-install
1818

19+
dinstall:
20+
$(MAKE) docker-install
21+
1922
docker-install:
20-
docker exec webinc-postgres /sql-extensions/install.sh
23+
docker exec launchql-postgres /sql-extensions/install.sh
2124

2225
k8-install:
2326
$(eval POD_NAME := $(shell kubectl get pods -l app=postgres -n webinc -o jsonpath="{.items[*].metadata.name}"))
2427
kubectl exec -n webinc -it $(POD_NAME) /sql-extensions/install.sh
2528

2629
all:
27-
./build.sh skitch package --version 0.0.1
28-
./build.sh skitch plan
30+
./build.sh lql package --version 0.0.1
31+
./build.sh lql plan
2932

3033
dump:
31-
skitch dump --deps --project dbs --path $(WEBINC_PATH)/services/packages/graphql-server-service/bootstrap/app.sql
34+
lql dump --deps --project dbs --path $(WEBINC_PATH)/services/packages/graphql-server-service/bootstrap/app.sql
3235

3336
deploy:
34-
@echo skitch deploy --recursive --createdb --yes --project dbs --database webinc-db
37+
@echo lql deploy --recursive --createdb --yes --project dbs --database launchql-db
38+
@echo lql deploy --recursive --createdb --yes --project dbs_rls --database launchql-db
39+
40+
generate:
41+
@cd packages/db_text && ./generate/generate.js
42+
@cd packages/db_text && lql package --version 0.0.1
43+
@cd packages/db_utils && lql package --version 0.0.1
44+
@cd packages/db_deps && lql package --version 0.0.1
45+
@cd packages/db_migrate && lql package --version 0.0.1
46+
$(MAKE) install
47+
48+
gen:
49+
@cd packages/db_text && ./generate/generate.js

bootstrap-roles.sql

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,62 @@
1-
CREATE ROLE administrator;
1+
-- anonymous
22
CREATE ROLE anonymous;
3+
4+
ALTER USER anonymous WITH NOCREATEDB;
5+
6+
ALTER USER anonymous WITH NOSUPERUSER;
7+
8+
ALTER USER anonymous WITH NOCREATEROLE;
9+
10+
ALTER USER anonymous WITH NOLOGIN;
11+
12+
ALTER USER anonymous WITH NOREPLICATION;
13+
14+
ALTER USER anonymous WITH NOBYPASSRLS;
15+
16+
-- authenticated
317
CREATE ROLE authenticated;
18+
19+
ALTER USER authenticated WITH NOCREATEDB;
20+
21+
ALTER USER authenticated WITH NOSUPERUSER;
22+
23+
ALTER USER authenticated WITH NOCREATEROLE;
24+
25+
ALTER USER authenticated WITH NOLOGIN;
26+
27+
ALTER USER authenticated WITH NOREPLICATION;
28+
29+
ALTER USER authenticated WITH NOBYPASSRLS;
30+
31+
-- administrator
32+
CREATE ROLE administrator;
33+
34+
ALTER USER administrator WITH NOCREATEDB;
35+
36+
ALTER USER administrator WITH NOSUPERUSER;
37+
38+
ALTER USER administrator WITH NOCREATEROLE;
39+
40+
ALTER USER administrator WITH NOLOGIN;
41+
42+
ALTER USER administrator WITH NOREPLICATION;
43+
44+
-- they CAN bypass RLS
45+
ALTER USER administrator WITH BYPASSRLS;
46+
47+
-- app user
448
CREATE ROLE app_user LOGIN PASSWORD 'app_password';
49+
550
GRANT anonymous TO app_user;
51+
652
GRANT authenticated TO app_user;
53+
54+
-- admin user
55+
CREATE ROLE app_admin LOGIN PASSWORD 'admin_password';
56+
57+
GRANT anonymous TO administrator;
58+
59+
GRANT authenticated TO administrator;
60+
61+
GRANT administrator TO app_admin;
62+

docker-compose.yml

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '2'
22
services:
33
postgres:
4-
container_name: webinc-postgres
5-
image: pyramation/postgres-plv8
4+
container_name: launchql-postgres
5+
image: pyramation/postgres
66
environment:
77
- "POSTGRES_USER=postgres"
88
- "POSTGRES_PASSWORD=password"
@@ -12,37 +12,3 @@ services:
1212
- "5432"
1313
volumes:
1414
- ./packages:/sql-extensions
15-
- ./node_modules:/sql-modules
16-
# prest:
17-
# container_name: webinc-prest
18-
# image: prest/prest
19-
# links:
20-
# - "postgres:webinc-postgres"
21-
# environment:
22-
# - PREST_DEBUG=true # remove comment for enable DEBUG mode (disable JWT)
23-
# - PREST_PG_HOST=postgres
24-
# - PREST_PG_USER=postgres
25-
# - PREST_PG_PASS=password
26-
# - PREST_PG_DATABASE=webinc-db
27-
# - PREST_PG_PORT=5432
28-
# - PREST_JWT_DEFAULT=false # remove if need jwt
29-
# depends_on:
30-
# - postgres
31-
# ports:
32-
# - "3333:3000"
33-
# postgrest:
34-
# container_name: webinc-postgrest
35-
# image: postgrest/postgrest:latest
36-
# ports:
37-
# - "4444:3000"
38-
# environment:
39-
# # The standard connection URI format, documented at
40-
# # https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
41-
# - PGRST_DB_URI=postgres://postgres:password@postgres:5432/webinc-db
42-
# # The name of which database schema to expose to REST clients
43-
# - PGRST_DB_SCHEMA=collections_public
44-
# # The database role to use when no client authentication is provided
45-
# - PGRST_DB_ANON_ROLE=postgres
46-
# depends_on:
47-
# - postgres
48-
# restart: always

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
2-
"name": "webinc",
2+
"name": "webql",
33
"dependencies": {
4-
"skitch-extension-defaults": "latest",
5-
"skitch-extension-default-roles": "latest",
6-
"skitch-extension-verify": "latest",
7-
"skitch-extension-utils": "latest"
84
}
9-
}
5+
}

packages/dbs_rls/.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"plugins": [
3+
"dynamic-import-node",
4+
"syntax-dynamic-import",
5+
"transform-class-properties",
6+
"transform-object-rest-spread",
7+
"transform-regenerator",
8+
"transform-runtime"
9+
],
10+
"presets": ["env"]
11+
}

packages/dbs_rls/.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
PGDATABASE=testing-db
3+
PGTEMPLATE_DATABASE=testing-template-db
4+
PGHOST=localhost
5+
PGPASSWORD=password
6+
PGPORT=5432
7+
PGUSER=postgres
8+
APP_USER=app_user
9+
APP_PASSWORD=app_password
10+
PGEXTENSIONS=plpgsql,uuid-ossp,pgcrypto,dbs,skitch-extension-default-roles,skitch-extension-defaults,skitch-extension-utils,skitch-extension-verify,webql-projects,webql-roles

packages/dbs_rls/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EXTENSION = dbs_rls
2+
DATA = sql/dbs_rls--0.0.1.sql
3+
4+
PG_CONFIG = pg_config
5+
PGXS := $(shell $(PG_CONFIG) --pgxs)
6+
include $(PGXS)
7+

packages/dbs_rls/dbs_rls.control

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# dbs_rls extension
2+
comment = 'dbs_rls extension'
3+
default_version = '0.0.1'
4+
module_pathname = '$libdir/dbs_rls'
5+
requires = 'plpgsql,uuid-ossp,pgcrypto,dbs,skitch-extension-default-roles,skitch-extension-defaults,skitch-extension-utils,skitch-extension-verify,webql-projects,webql-roles'
6+
relocatable = false
7+
superuser = false
8+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Deploy schemas/collections_private/grants/grant_schema_to_authenticated to pg
2+
-- requires: schemas/collections_private/schema
3+
4+
BEGIN;
5+
GRANT USAGE ON SCHEMA collections_private TO authenticated, anonymous;
6+
GRANT EXECUTE ON FUNCTION collections_private.get_available_schema_name TO authenticated;
7+
GRANT EXECUTE ON FUNCTION collections_private.database_name_hash TO authenticated;
8+
GRANT EXECUTE ON FUNCTION collections_private.table_name_hash TO authenticated;
9+
GRANT EXECUTE ON FUNCTION collections_private.get_schema_name_by_database_id TO authenticated;
10+
GRANT EXECUTE ON FUNCTION collections_private.is_valid_type TO authenticated;
11+
COMMIT;
12+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Deploy schemas/collections_private/schema to pg
2+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Deploy schemas/collections_public/grants/grant_schema_to_authenticated to pg
2+
3+
-- requires: schemas/collections_public/schema
4+
5+
BEGIN;
6+
7+
GRANT USAGE ON SCHEMA collections_public TO authenticated;
8+
9+
COMMIT;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Deploy schemas/collections_public/schema to pg
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Deploy schemas/collections_public/tables/constraint/alterations/alter_table_add_project_id to pg
2+
3+
-- requires: schemas/collections_public/schema
4+
-- requires: schemas/collections_public/tables/constraint/table
5+
6+
BEGIN;
7+
8+
ALTER TABLE collections_public.constraint
9+
ADD COLUMN project_id uuid NOT NULL;
10+
11+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Deploy schemas/collections_public/tables/constraint/policies/enable_row_level_security to pg
2+
3+
-- requires: schemas/collections_public/schema
4+
-- requires: schemas/collections_public/tables/constraint/table
5+
6+
BEGIN;
7+
8+
ALTER TABLE collections_public.constraint
9+
ENABLE ROW LEVEL SECURITY;
10+
11+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- Deploy schemas/collections_public/tables/constraint/policies/project_constraint_policy to pg
2+
3+
-- requires: schemas/collections_public/schema
4+
-- requires: schemas/collections_public/tables/constraint/table
5+
-- requires: schemas/collections_public/tables/constraint/policies/enable_row_level_security
6+
-- requires: schemas/collections_public/tables/constraint/alterations/alter_table_add_project_id
7+
BEGIN;
8+
9+
CREATE POLICY can_select_constraint ON collections_public.constraint
10+
FOR SELECT
11+
USING (
12+
collaboration_private.permitted_on_project ('read', 'database', project_id)
13+
);
14+
15+
CREATE POLICY can_insert_constraint ON collections_public.constraint
16+
FOR INSERT
17+
WITH CHECK (
18+
collaboration_private.permitted_on_project ('add', 'database', project_id)
19+
);
20+
21+
CREATE POLICY can_update_constraint ON collections_public.constraint
22+
FOR UPDATE
23+
USING (
24+
collaboration_private.permitted_on_project ('edit', 'database', project_id)
25+
);
26+
27+
CREATE POLICY can_delete_constraint ON collections_public.constraint
28+
FOR DELETE
29+
USING (
30+
collaboration_private.permitted_on_project ('destroy', 'database', project_id)
31+
);
32+
33+
34+
GRANT INSERT ON TABLE collections_public.constraint TO authenticated;
35+
GRANT SELECT ON TABLE collections_public.constraint TO authenticated;
36+
GRANT UPDATE ON TABLE collections_public.constraint TO authenticated;
37+
GRANT DELETE ON TABLE collections_public.constraint TO authenticated;
38+
39+
40+
COMMIT;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Deploy schemas/collections_public/tables/constraint/table to pg
2+
3+
-- requires: schemas/collections_public/schema
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- Deploy schemas/collections_public/tables/constraint/triggers/before_insert_constraint_set_project_id to pg
2+
3+
-- requires: schemas/collections_public/schema
4+
-- requires: schemas/collections_public/tables/constraint/table
5+
-- requires: schemas/collections_public/tables/constraint/alterations/alter_table_add_project_id
6+
7+
BEGIN;
8+
9+
CREATE FUNCTION collections_private.tg_before_insert_constraint_set_project_id()
10+
RETURNS TRIGGER AS $$
11+
DECLARE
12+
proj_id uuid;
13+
BEGIN
14+
SELECT project_id FROM collections_public.table
15+
WHERE id = NEW.table_id
16+
INTO proj_id;
17+
18+
NEW.project_id = proj_id;
19+
20+
RETURN NEW;
21+
END;
22+
$$
23+
LANGUAGE 'plpgsql' VOLATILE;
24+
25+
CREATE TRIGGER before_insert_constraint_set_project_id
26+
BEFORE INSERT ON collections_public.constraint
27+
FOR EACH ROW
28+
EXECUTE PROCEDURE collections_private.tg_before_insert_constraint_set_project_id ();
29+
30+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Deploy schemas/collections_public/tables/database/alterations/add_foreign_key_project_id to pg
2+
3+
-- requires: schemas/collections_public/schema
4+
-- requires: schemas/projects_public/schema
5+
-- requires: schemas/collections_public/tables/database/table
6+
-- requires: schemas/projects_public/tables/project/table
7+
-- requires: schemas/collections_public/tables/database/alterations/alter_table_add_project_id
8+
9+
BEGIN;
10+
11+
12+
ALTER TABLE collections_public.database
13+
ADD CONSTRAINT fk_collections_public_database_project_id
14+
FOREIGN KEY (project_id)
15+
REFERENCES projects_public.project (id)
16+
ON DELETE CASCADE;
17+
18+
19+
COMMIT;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Deploy schemas/collections_public/tables/database/alterations/alter_table_add_project_id to pg
2+
3+
-- requires: schemas/collections_public/schema
4+
-- requires: schemas/collections_public/tables/database/table
5+
6+
BEGIN;
7+
8+
ALTER TABLE collections_public.database
9+
ADD COLUMN project_id uuid NOT NULL;
10+
11+
COMMIT;

0 commit comments

Comments
 (0)