Skip to content

Commit

Permalink
fixup: use default dbname
Browse files Browse the repository at this point in the history
  • Loading branch information
penguincoder committed Jul 21, 2023
1 parent b0ba749 commit b2ac383
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/modules/services/postgres.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let
echo $dbAlreadyExists
if [ 1 -ne "$dbAlreadyExists" ]; then
echo "Creating database: ${database.name}"
echo 'create database "${database.name}";' | psql
echo 'create database "${database.name}";' | psql --dbname postgres
${lib.optionalString (database.schema != null) ''
Expand Down Expand Up @@ -57,12 +57,12 @@ let
cfg.initialDatabases)
else
lib.optionalString cfg.createDatabase ''
echo "CREATE DATABASE ''${USER:-$(id -nu)};" | psql '';
echo "CREATE DATABASE ''${USER:-$(id -nu)};" | psql --dbname postgres'';

runInitialScript =
if cfg.initialScript != null then
''
echo ${lib.escapeShellArg cfg.initialScript} | psql
echo ${lib.escapeShellArg cfg.initialScript} | psql --dbname postgres
''
else
"";
Expand All @@ -85,23 +85,29 @@ let
if [[ ! -d "$PGDATA" ]]; then
initdb ${lib.concatStringsSep " " cfg.initdbArgs}
echo
echo "PostgreSQL init process complete; ready for start up."
echo
fi
# Setup config
cp ${configFile} "$PGDATA/postgresql.conf"
if [[ ! -f "$PGDATA/.configured" ]]; then
touch "$PGDATA/.configured"
echo
echo "PostgreSQL appears unconfigured; going to run initialization scripts."
echo
pg_ctl -D "$PGDATA" -w start
${setupInitialDatabases}
${runInitialScript}
pg_ctl -D "$PGDATA" -m fast -w stop
else
echo
echo "PostgreSQL Database directory appears to contain a database; Skipping initialization"
echo
fi
'';
startScript = pkgs.writeShellScriptBin "start-postgres" ''
Expand Down

0 comments on commit b2ac383

Please sign in to comment.