Extend direnv to create postgres dir

This commit is contained in:
Andreas Zweili 2023-07-12 23:16:32 +02:00
parent 0eea48d727
commit e4b064b830
1 changed files with 10 additions and 0 deletions

10
.envrc
View File

@ -1,2 +1,12 @@
use flake
eval "$shellHook"
layout_postgres() {
export PGDATA="$(direnv_layout_dir)/postgres"
export PGHOST="$PGDATA"
if [[ ! -d "$PGDATA" ]]; then
initdb
echo -e "listen_addresses = ''\nunix_socket_directories = '$PGHOST'" >> "$PGDATA/postgresql.conf"
echo "CREATE DATABASE $USER;" | postgres --single -E postgres
fi
}
layout postgres