This commit is contained in:
2025-03-17 14:01:53 +04:00
parent 4e2c2d1728
commit 2ace2216dd

View File

@@ -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 { setupScript = pkgs.writeShellApplication {
name = "setup-postgres"; name = "setup-postgres";
runtimeInputs = [ runtimeInputs = [
@@ -129,6 +136,7 @@ in
echo "PostgreSQL is setting up the initial database" echo "PostgreSQL is setting up the initial database"
echo echo
pg_ctl -w start -o "-c listen_addresses= -p ${builtins.toString port}" pg_ctl -w start -o "-c listen_addresses= -p ${builtins.toString port}"
${setupInitialDatabases}
pg_ctl -m fast -w stop pg_ctl -m fast -w stop
else else
echo echo