From d5996574b62cb446b2796dd13385726a5e8a3d63 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Sun, 28 Aug 2022 22:33:19 +0900 Subject: [PATCH] grant anon role --- compose.yml | 2 +- db/migrations/0_init.sql | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compose.yml b/compose.yml index 760847e..b685061 100644 --- a/compose.yml +++ b/compose.yml @@ -7,7 +7,7 @@ services: environment: PGRST_DB_URI: postgresql://postgres:${POSTGRES_PASSWORD}@/postgres?host=/var/run/postgresql PGRST_DB_SCHEMA: public - PGRST_DB_ANON_ROLE: postgres + PGRST_DB_ANON_ROLE: anon volumes: - postgres_socket:/var/run/postgresql depends_on: [db] diff --git a/db/migrations/0_init.sql b/db/migrations/0_init.sql index 31fd357..b6b6c0f 100644 --- a/db/migrations/0_init.sql +++ b/db/migrations/0_init.sql @@ -1,4 +1,7 @@ -- migrate:up +CREATE ROLE anon; +ALTER ROLE anon SET statement_timeout = '1s'; + CREATE FUNCTION update_timestamp() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN NEW.updated = CURRENT_TIMESTAMP; @@ -14,10 +17,12 @@ CREATE TABLE pages ( updated TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP ); +GRANT ALL ON pages TO anon; + CREATE TRIGGER pages_updated BEFORE UPDATE ON pages FOR EACH ROW EXECUTE PROCEDURE update_timestamp(); -- migrate:down -DROP TRIGGER pages_updated ON pages; DROP TABLE pages; DROP FUNCTION update_timestamp(); +DROP ROLE anon;