aboutsummaryrefslogtreecommitdiffstats
path: root/postgrest
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@eficode.com>2020-04-26 15:48:24 +0300
committerJan Tuomi <jan.tuomi@eficode.com>2020-04-26 15:48:24 +0300
commit55f725a502011155f0943f2340ef3763f014ccc0 (patch)
treec1915fd2c3f67e93b3fd406d018583bc6b050baa /postgrest
Initial commit
Diffstat (limited to 'postgrest')
-rw-r--r--postgrest/Dockerfile6
-rw-r--r--postgrest/migrations/001-initial.sql1
-rw-r--r--postgrest/migrations/002-todos.sql9
-rw-r--r--postgrest/migrations/003-roles.sql15
-rwxr-xr-xpostgrest/postgrestbin0 -> 44823944 bytes
-rw-r--r--postgrest/postgrest.conf4
-rwxr-xr-xpostgrest/start-postgrest.sh5
7 files changed, 40 insertions, 0 deletions
diff --git a/postgrest/Dockerfile b/postgrest/Dockerfile
new file mode 100644
index 0000000..5e6abac
--- /dev/null
+++ b/postgrest/Dockerfile
@@ -0,0 +1,6 @@
+FROM ubuntu:18.04
+
+WORKDIR /app
+RUN apt-get update && apt-get install -y libpq-dev gettext
+ADD postgrest postgrest.conf start-postgrest.sh ./
+CMD ["./start-postgrest.sh"]
diff --git a/postgrest/migrations/001-initial.sql b/postgrest/migrations/001-initial.sql
new file mode 100644
index 0000000..be41377
--- /dev/null
+++ b/postgrest/migrations/001-initial.sql
@@ -0,0 +1 @@
+create schema api;
diff --git a/postgrest/migrations/002-todos.sql b/postgrest/migrations/002-todos.sql
new file mode 100644
index 0000000..5efb477
--- /dev/null
+++ b/postgrest/migrations/002-todos.sql
@@ -0,0 +1,9 @@
+create table api.todos (
+ id serial primary key,
+ done boolean not null default false,
+ task text not null,
+ due timestamptz
+);
+
+-- insert into api.todos (task) values
+-- ('finish tutorial 0'), ('pat self on back');
diff --git a/postgrest/migrations/003-roles.sql b/postgrest/migrations/003-roles.sql
new file mode 100644
index 0000000..86e49f0
--- /dev/null
+++ b/postgrest/migrations/003-roles.sql
@@ -0,0 +1,15 @@
+-- authenticator role
+create role authenticator noinherit login password 'mysecretpassword';
+
+-- web_anon role
+create role web_anon nologin;
+grant usage on schema api to web_anon;
+grant web_anon to authenticator;
+-- grant select on api.todos to web_anon;
+
+-- todo_user role
+create role todo_user nologin;
+grant usage on schema api to todo_user;
+grant all on api.todos to todo_user;
+grant usage, select on sequence api.todos_id_seq to todo_user;
+grant todo_user to authenticator;
diff --git a/postgrest/postgrest b/postgrest/postgrest
new file mode 100755
index 0000000..9050387
--- /dev/null
+++ b/postgrest/postgrest
Binary files differ
diff --git a/postgrest/postgrest.conf b/postgrest/postgrest.conf
new file mode 100644
index 0000000..638b528
--- /dev/null
+++ b/postgrest/postgrest.conf
@@ -0,0 +1,4 @@
+db-uri = "postgres://authenticator:mysecretpassword@postgres:5432/postgres"
+db-schema = "api"
+db-anon-role = "web_anon"
+jwt-secret = "${JWT_SECRET}"
diff --git a/postgrest/start-postgrest.sh b/postgrest/start-postgrest.sh
new file mode 100755
index 0000000..5995898
--- /dev/null
+++ b/postgrest/start-postgrest.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+envsubst < postgrest.conf > postgrest.conf.tmp
+mv postgrest.conf.tmp postgrest.conf
+./postgrest postgrest.conf