nix: Simplify with_tmp_db
This commit is contained in:
@@ -60,15 +60,9 @@ let
|
|||||||
|
|
||||||
log "Starting the database cluster..."
|
log "Starting the database cluster..."
|
||||||
# Instead of listening on a local port, we will listen on a unix domain socket.
|
# Instead of listening on a local port, we will listen on a unix domain socket.
|
||||||
pg_ctl -l "$tmpdir/db.log" start -o "-F -c listen_addresses=\"\" -k $PGHOST" \
|
pg_ctl -l "$tmpdir/db.log" -w start -o "-F -c listen_addresses=\"\" -k $PGHOST" \
|
||||||
>> "$setuplog"
|
>> "$setuplog"
|
||||||
|
|
||||||
log "Waiting for the database cluster to be ready..."
|
|
||||||
# Waiting is required for older versions of Postgres (< 10).
|
|
||||||
until pg_isready >> "$setuplog"; do
|
|
||||||
sleep 0.1
|
|
||||||
done
|
|
||||||
|
|
||||||
stop () {
|
stop () {
|
||||||
log "Stopping the database cluster..."
|
log "Stopping the database cluster..."
|
||||||
pg_ctl stop -m i >> "$setuplog"
|
pg_ctl stop -m i >> "$setuplog"
|
||||||
|
|||||||
+3
-16
@@ -69,23 +69,10 @@ PGTZ=UTC initdb --no-locale --encoding=UTF8 --nosync -U "$PGUSER" --auth=trust \
|
|||||||
|
|
||||||
log "Starting the database cluster..."
|
log "Starting the database cluster..."
|
||||||
# Instead of listening on a local port, we will listen on a unix domain socket.
|
# Instead of listening on a local port, we will listen on a unix domain socket.
|
||||||
pg_ctl -l "$dblog" start -o "-F -c listen_addresses=\"\" -k $PGHOST" \
|
pg_ctl -l "$dblog" -w start -o "-F -c listen_addresses=\"\" -k $PGHOST" \
|
||||||
>> "$setuplog"
|
>> "$setuplog"
|
||||||
|
|
||||||
log "Waiting for the database cluster to be ready..."
|
|
||||||
# Waiting is required for older versions of Postgres (< 10).
|
|
||||||
until pg_isready >> "$setuplog"; do
|
|
||||||
sleep 0.1
|
|
||||||
done
|
|
||||||
|
|
||||||
stopped=0
|
|
||||||
stop() {
|
stop() {
|
||||||
# cleaning up once is enough; otherwise we get some errors
|
|
||||||
if [ $stopped -eq 1 ]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
stopped=1
|
|
||||||
|
|
||||||
log "Stopping the database cluster..."
|
log "Stopping the database cluster..."
|
||||||
pg_ctl stop -m i >> "$setuplog"
|
pg_ctl stop -m i >> "$setuplog"
|
||||||
|
|
||||||
@@ -96,7 +83,7 @@ stop() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
trap stop sigint sigterm exit
|
trap stop EXIT
|
||||||
|
|
||||||
log "Loading fixtures..."
|
log "Loading fixtures..."
|
||||||
psql -v ON_ERROR_STOP=1 -f test/fixtures/load.sql >> "$setuplog"
|
psql -v ON_ERROR_STOP=1 -f test/fixtures/load.sql >> "$setuplog"
|
||||||
@@ -106,4 +93,4 @@ log "Done. Running command..."
|
|||||||
# make sure that the database is shut down and the temporary directory is
|
# make sure that the database is shut down and the temporary directory is
|
||||||
# deleted when the command is done. This is also why we don't `exec` the
|
# deleted when the command is done. This is also why we don't `exec` the
|
||||||
# command - our trap would be lost if we did that.
|
# command - our trap would be lost if we did that.
|
||||||
"$@"
|
("$@")
|
||||||
|
|||||||
Reference in New Issue
Block a user