mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
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:
committed by
Tim Abbott
parent
efd22fd2ae
commit
5290519a62
@@ -27,7 +27,7 @@ def get_loc_over_ssh(host, func):
|
||||
# type: (str, str) -> str
|
||||
try:
|
||||
return subprocess.check_output(['ssh', host,
|
||||
'psql zulip -t -c "SELECT %s()"' % (func,)],
|
||||
'psql -v ON_ERROR_STOP=1 zulip -t -c "SELECT %s()"' % (func,)],
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
||||
@@ -18,7 +18,8 @@ def report(state, msg):
|
||||
print("%s: %s" % (state, msg))
|
||||
exit(states[state])
|
||||
|
||||
if subprocess.check_output(['psql', 'postgres', '-t', '-c',
|
||||
if subprocess.check_output(['psql', '-v', 'ON_ERROR_STOP=1',
|
||||
'postgres', '-t', '-c',
|
||||
'SELECT pg_is_in_recovery()']).strip() != b'f':
|
||||
report('OK', 'this is not the primary')
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ def run(args, dry_run=False):
|
||||
sys.exit(1)
|
||||
return stdout.decode()
|
||||
|
||||
recovery_val = run(['psql', '-t', '-c', 'select pg_is_in_recovery()']).strip()
|
||||
recovery_val = run(['psql', '-v', 'ON_ERROR_STOP=1', '-t', '-c', 'SELECT pg_is_in_recovery()']).strip()
|
||||
# Assertion to check that we're extracting the value correctly.
|
||||
assert recovery_val in ['t', 'f']
|
||||
if recovery_val == 't':
|
||||
|
||||
@@ -17,7 +17,7 @@ GRANT USAGE ON SCHEMA pgroonga TO zulip;
|
||||
"
|
||||
|
||||
if [ -f /.dockerenv ]; then
|
||||
echo "$DATABASE_CREATE" | psql
|
||||
echo "$DATABASE_CREATE" | psql -v ON_ERROR_STOP=1 -e
|
||||
else
|
||||
echo "$DATABASE_CREATE" | su postgres -c psql
|
||||
echo "$DATABASE_CREATE" | su postgres -c 'psql -v ON_ERROR_STOP=1 -e'
|
||||
fi
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -26,6 +26,6 @@ root)
|
||||
;;
|
||||
esac
|
||||
|
||||
"${psql[@]}" <<EOF
|
||||
"${psql[@]}" -v ON_ERROR_STOP=1 <<EOF
|
||||
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname IN ($tables);
|
||||
EOF
|
||||
|
||||
@@ -4,7 +4,7 @@ set -x
|
||||
|
||||
"$(dirname "$0")/../scripts/setup/terminate-psql-sessions" zulip zulip zulip_base
|
||||
|
||||
psql -h localhost postgres zulip <<EOF
|
||||
psql -v ON_ERROR_STOP=1 -e -h localhost postgres zulip <<EOF
|
||||
DROP DATABASE IF EXISTS zulip;
|
||||
CREATE DATABASE zulip TEMPLATE zulip_base;
|
||||
EOF
|
||||
|
||||
@@ -5,7 +5,7 @@ export DJANGO_SETTINGS_MODULE=zproject.test_settings
|
||||
|
||||
create_template_database()
|
||||
{
|
||||
psql -h localhost postgres zulip_test << EOF
|
||||
psql -v ON_ERROR_STOP=1 -h localhost postgres zulip_test << EOF
|
||||
DROP DATABASE IF EXISTS zulip_test_template;
|
||||
CREATE DATABASE zulip_test_template TEMPLATE zulip_test;
|
||||
EOF
|
||||
@@ -13,7 +13,7 @@ EOF
|
||||
|
||||
if [ "$1" != "--force" ]; then
|
||||
"$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" zulip zulip_test zulip_test_base zulip_test_template
|
||||
psql -h localhost postgres zulip_test << EOF
|
||||
psql -v ON_ERROR_STOP=1 -h localhost postgres zulip_test << EOF
|
||||
DROP DATABASE IF EXISTS zulip_test;
|
||||
CREATE DATABASE zulip_test TEMPLATE zulip_test_template;
|
||||
EOF
|
||||
@@ -25,7 +25,7 @@ mkdir -p zerver/tests/fixtures
|
||||
|
||||
"$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" zulip zulip_test zulip_test_base zulip_test_template
|
||||
|
||||
psql -h localhost postgres zulip_test <<EOF
|
||||
psql -v ON_ERROR_STOP=1 -h localhost postgres zulip_test <<EOF
|
||||
DROP DATABASE IF EXISTS zulip_test;
|
||||
CREATE DATABASE zulip_test TEMPLATE zulip_test_base;
|
||||
EOF
|
||||
|
||||
@@ -49,7 +49,7 @@ if ! pg_isready -U "$POSTGRES_USER" -q; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
"${ROOT_POSTGRES[@]}" "$DEFAULT_DB" << EOF
|
||||
"${ROOT_POSTGRES[@]}" -v ON_ERROR_STOP=1 -e "$DEFAULT_DB" << EOF
|
||||
DO \$\$BEGIN
|
||||
CREATE USER $USERNAME;
|
||||
EXCEPTION WHEN duplicate_object THEN
|
||||
@@ -80,23 +80,23 @@ chmod go-rw ~/.pgpass
|
||||
|
||||
"$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" "$USERNAME" "$DBNAME" "$DBNAME_BASE"
|
||||
|
||||
psql -h localhost postgres "$USERNAME" <<EOF
|
||||
psql -v ON_ERROR_STOP=1 -e -h localhost postgres "$USERNAME" <<EOF
|
||||
DROP DATABASE IF EXISTS $DBNAME;
|
||||
DROP DATABASE IF EXISTS $DBNAME_BASE;
|
||||
CREATE DATABASE $DBNAME_BASE
|
||||
EOF
|
||||
|
||||
psql -h localhost "$DBNAME_BASE" "$USERNAME" <<EOF
|
||||
psql -v ON_ERROR_STOP=1 -e -h localhost "$DBNAME_BASE" "$USERNAME" <<EOF
|
||||
CREATE SCHEMA zulip;
|
||||
EOF
|
||||
|
||||
"${ROOT_POSTGRES[@]}" "$DBNAME_BASE" << EOF
|
||||
"${ROOT_POSTGRES[@]}" -v ON_ERROR_STOP=1 -e "$DBNAME_BASE" << EOF
|
||||
CREATE EXTENSION tsearch_extras SCHEMA zulip;
|
||||
CREATE EXTENSION pgroonga;
|
||||
GRANT USAGE ON SCHEMA pgroonga TO $USERNAME;
|
||||
EOF
|
||||
|
||||
psql -h localhost postgres "$USERNAME" <<EOF
|
||||
psql -v ON_ERROR_STOP=1 -e -h localhost postgres "$USERNAME" <<EOF
|
||||
CREATE DATABASE $DBNAME TEMPLATE $DBNAME_BASE;
|
||||
EOF
|
||||
|
||||
|
||||
Reference in New Issue
Block a user