prettier devShell hook

This commit is contained in:
Rachel Lambda Samuelsson 2023-08-08 17:42:57 +02:00
parent 0c5deddbc0
commit 751988225b

View File

@ -19,14 +19,31 @@
packages = [ packages.default packages.postgres ]; packages = [ packages.default packages.postgres ];
shellHook = '' shellHook = ''
set -e set -e
[ -d ./matabas-db ] || pg_ctl initdb --pgdata=./matabas-db
mkdir -p ./matabas-db/socket
[ -f matabas-db/matabas.log ] && mv -f matabas-db/matabas.log{,.old} log() {
printf '\e[1m\e[38;5;87m==>\e[0m\e[1m %s.\e[0m\n' "$*"
}
log "Checking for existing postgres directory"
[ -d ./matabas-db ] || {
log "Non-existent, creating postgres directory (./matabas-db)"
pg_ctl initdb --pgdata=./matabas-db
}
[ -f matabas-db/matabas.log ] && {
log "Moving logs from last session into log archive (./matabas-db/matabas.log.old)"
cat matabas-db/matabas.log >> matabas-db/matabas.log.old
rm -f matabas-db/matabas.log
}
log "Starting postgres"
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137" pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137"
trap 'pg_ctl stop --pgdata=./matabas-db' EXIT trap 'log "Stopping postgres" && pg_ctl stop --pgdata=./matabas-db' EXIT
createdb -p 2137 matabas || : 3 log "Creating database"
createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Database already exists, not overwriting"
log "Environment ready!"
set +e set +e
''; '';