Compare commits

...

3 commits

Author SHA1 Message Date
Jakob Lechner
1660118c2e Fix database privileges
Fixes psycopg2.errors.InsufficientPrivilege: permission denied for
schema public
2025-07-20 17:44:33 +02:00
Jakob Lechner
f8e585c83f Add postgresql as service requirement 2025-07-20 17:21:24 +02:00
Jakob Lechner
8453ab9ae9 Add database initialization
Runs fieldpoc with `--init` if there are no tables in the database.
2025-07-20 17:21:24 +02:00

View file

@ -31,7 +31,7 @@ in {
systemd.services.fieldpoc = {
description = "Fieldpoc daemon";
wantedBy = [ "multi-user.target" ];
requires = [ "network-online.target" "yate.service" ];
requires = [ "network-online.target" "yate.service" "postgresql.service" ];
after = [ "network-online.target" "yate.service" ];
serviceConfig = {
@ -78,6 +78,10 @@ in {
if [ ! -f "/var/lib/fieldpoc/extensions.json" ]; then
echo '{"extensions": {}}' > /var/lib/fieldpoc/extensions.json
fi
if [ $(${config.services.postgresql.finalPackage}/bin/psql -q -t -A -c "select count(*) from information_schema.tables where table_schema='fieldpoc';") -eq 0 ]; then
${pkgs.fieldpoc}/bin/fieldpoc -c /run/fieldpoc/config.json --debug --init
fi
'';
};
@ -94,6 +98,7 @@ in {
CREATE ROLE fieldpoc WITH LOGIN PASSWORD 'fieldpoc' CREATEDB;
CREATE DATABASE fieldpoc;
GRANT ALL PRIVILEGES ON DATABASE fieldpoc TO fieldpoc;
GRANT USAGE, CREATE ON SCHEMA public TO fieldpoc;
'';
};