aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2022-11-29 11:15:49 -0500
committerNathan Perry <np@nathanperry.dev>2022-11-29 11:15:49 -0500
commit6181fc78cd125c48584e933a60188ec51819130d (patch)
tree0357d1e5b59530b2da83271c8a2021df86c8eb72 /flake.nix
parentf7155b7372f9007a378cb07d5acdc1abcc8cc7f1 (diff)
nix: ensure ownership on start
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix9
1 files changed, 9 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
index 36a50dd..32b6024 100644
--- a/flake.nix
+++ b/flake.nix
@@ -269,9 +269,18 @@
SELECT 'CREATE DATABASE ${cfg.postgres.db}'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${cfg.postgres.db}')\gexec
+
+ ALTER DATABASE ${cfg.postgres.db} OWNER TO ${cfg.user};
EOF
echo 'CREATE EXTENSION IF NOT EXISTS pgcrypto' | ${invokePsql} ${cfg.postgres.db}
+
+ for tbl in $(psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" ${cfg.postgres.db}) \
+ $(psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" ${cfg.postgres.db}) \
+ $(psql -qAt -c "select table_name from information_schema.views where table_schema = 'public';" ${cfg.postgres.db}) ;
+ do
+ psql -c "alter table \"$tbl\" owner to ${cfg.user}" ${cfg.postgres.db};
+ done
'';
in "+${preStart}";