refactor(postgres): replace string argument with attrset for connectionURI (#146)

for justification, see:
https://github.com/juspay/services-flake/pull/143#discussion_r1521290361
This commit is contained in:
Shivaraj B H 2024-03-13 00:40:13 +05:30 committed by GitHub
parent fb48b6b612
commit 18f9decf13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 9 deletions

View File

@ -29,12 +29,7 @@
settings.processes.pgweb = { settings.processes.pgweb = {
command = pkgs.pgweb; command = pkgs.pgweb;
depends_on."northwind".condition = "process_healthy"; depends_on."northwind".condition = "process_healthy";
environment.PGWEB_DATABASE_URL = environment.PGWEB_DATABASE_URL = config.services.postgres.northwind.connectionURI { dbName = "sample"; };
let
inherit (config.services.postgres.northwind)
listen_addresses port;
in
"postgres://$USER@${listen_addresses}:${builtins.toString port}/sample";
}; };
}; };
}; };

View File

@ -45,7 +45,7 @@
pgcfg = config.services.postgres.pg1; pgcfg = config.services.postgres.pg1;
in in
{ {
environment.PGWEB_DATABASE_URL = pgcfg.connectionURI dbName; environment.PGWEB_DATABASE_URL = pgcfg.connectionURI { inherit dbName; };
command = pkgs.pgweb; command = pkgs.pgweb;
depends_on."pg1".condition = "process_healthy"; depends_on."pg1".condition = "process_healthy";
}; };

View File

@ -60,8 +60,11 @@ in
connectionURI = lib.mkOption { connectionURI = lib.mkOption {
type = lib.types.functionTo lib.types.str; type = lib.types.functionTo lib.types.str;
readOnly = true; readOnly = true;
default = dbName: "postgres://${config.listen_addresses}:${builtins.toString config.port}/${dbName}"; default = { dbName, ... }: "postgres://${config.listen_addresses}:${builtins.toString config.port}/${dbName}";
description = "A function that accepts database name and returns the [postgres connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS)"; description = ''
A function that accepts an attrset overriding the connection parameters
and returns the [postgres connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS)
'';
}; };
hbaConf = hbaConf =