add init
This commit is contained in:
8
lib.nix
8
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
|
||||
|
||||
Reference in New Issue
Block a user