From 2ace2216dd66c7b40287c5b38ab7cbf784343bdd Mon Sep 17 00:00:00 2001 From: Nikkuss Date: Mon, 17 Mar 2025 14:01:53 +0400 Subject: [PATCH] add init --- lib.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib.nix b/lib.nix index d0ff630..4dd3cdc 100644 --- a/lib.nix +++ b/lib.nix @@ -108,6 +108,13 @@ in ) ); }; + setupInitialDatabases = if initialDatabases != [] then ( + lib.concatMapStrings (db: '' + echo "Checking presence of database ${db.name}" + dbAlreadyExists="$(echo "SELECT 1 AS result FROM pg_database WHERE datname='${db.name}';" | psql --dbname postgres | ${pkgs.gnugrep}/bin/grep -c 'exists = "1"' || true)" + echo $dbAlreadyExists + '') initialDatabases + ); setupScript = pkgs.writeShellApplication { name = "setup-postgres"; runtimeInputs = [ @@ -129,6 +136,7 @@ in echo "PostgreSQL is setting up the initial database" echo pg_ctl -w start -o "-c listen_addresses= -p ${builtins.toString port}" + ${setupInitialDatabases} pg_ctl -m fast -w stop else echo