scripts: Always use ON_ERROR_STOP=1 when running psql.

Also use psql -e (--echo-queries) in scripts that use ‘set -x’, so
errors can be traced to a specific query from the output.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2019-04-01 16:00:57 -07:00
committed by Tim Abbott
parent efd22fd2ae
commit 5290519a62
9 changed files with 18 additions and 17 deletions

View File

@@ -14,7 +14,7 @@ POSTGRES_USER="${POSTGRES_USER:-postgres}"
# We have to do this because on production database zulip may not exist, so psql
# will fail with return code 2. Because set -e is on, this will cause the script
# to bail.
records=$(su "$POSTGRES_USER" -c "psql -Atc 'SELECT COUNT(*) FROM zulip.zerver_message;' zulip" | cat)
records=$(su "$POSTGRES_USER" -c "psql -v ON_ERROR_STOP=1 -Atc 'SELECT COUNT(*) FROM zulip.zerver_message;' zulip" | cat)
if [[ $records -gt 200 ]]
then
@@ -44,7 +44,7 @@ source "$(dirname "$0")/terminate-psql-sessions" postgres zulip zulip_base
# Make sure the current working directory is readable by postgres
cd /
su "$POSTGRES_USER" -c psql <<EOF
su "$POSTGRES_USER" -c 'psql -v ON_ERROR_STOP=1 -e' <<EOF
DROP DATABASE IF EXISTS zulip;
EOF