From 4dbabd14ac7b21a78e2e9a6c875dfc276fb6ccd1 Mon Sep 17 00:00:00 2001 From: SIAX Agent Date: Sat, 7 Nov 2026 17:29:03 +0100 Subject: [PATCH] fix(sql): 023 grants for canonical tables to app-role 0pt_app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 022 skapade tabellerna som 0pt_edge; appen kör som 0pt_app och fick 'permission denied'. Övriga 0pt-tabeller har explicita grants (inga default ACL), så kanoniska tabeller behöver samma. Idempotent och rollskyddad; RLS (FORCE) gäller fortfarande för 0pt_app. --- sql/023_canonical_grants.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sql/023_canonical_grants.sql diff --git a/sql/023_canonical_grants.sql b/sql/023_canonical_grants.sql new file mode 100644 index 0000000..8fe96b2 --- /dev/null +++ b/sql/023_canonical_grants.sql @@ -0,0 +1,19 @@ +-- 023_canonical_grants.sql — app-role privileges for 022 canonical tables. +-- +-- Tables created by a manual psql migration are owned by the migrating role +-- (0pt_edge); the running application connects as 0pt_app. Existing 0pt tables +-- carry explicit grants rather than default ACLs, so the canonical tables need +-- the same treatment. RLS still applies to 0pt_app (FORCE is on); this only +-- grants the statement privileges, not row visibility. +-- +-- Idempotent and role-guarded: no-op in environments without the app role. + +DO $$ +BEGIN + IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '0pt_app') THEN + GRANT SELECT, INSERT, UPDATE, DELETE + ON opt_canonical_entities, opt_canonical_facts, opt_canonical_relations + TO 0pt_app; + END IF; +END +$$;