From ed70b62ea846122f4a0a4dbdc135544cc558da40 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 8 Mar 2024 12:38:45 -0500 Subject: [PATCH] create-database: Treat "zulip" db without "zerver_messages" as empty. A user who somehow got an empty `zulip` database, but without a `zerver_messages` table in it, would get stuck in the installer at: ``` ++ su postgres -c 'cd / && psql -v ON_ERROR_STOP=1 -Atc '\''SELECT COUNT(*) FROM zulip.zerver_message;'\'' zulip' ERROR: relation "zulip.zerver_message" does not exist LINE 1: SELECT COUNT(*) FROM zulip.zerver_message; ^ + records= ``` Treat a failure to select from `zerver_messages` as having 0 messages, and continue with the `DROP DATABASE IF EXISTS` / `CREATE DATABASE` that `create-db.sql` usually does. Fixes: #29110. --- scripts/setup/create-database | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup/create-database b/scripts/setup/create-database index b2e6fb9688..3c3de04ff8 100755 --- a/scripts/setup/create-database +++ b/scripts/setup/create-database @@ -15,7 +15,7 @@ DATABASE_NAME=$(crudini --get /etc/zulip/zulip.conf postgresql database_name 2>/ DATABASE_USER=$(crudini --get /etc/zulip/zulip.conf postgresql database_user 2>/dev/null || echo zulip) if [ "$(su "$POSTGRES_USER" -c "cd / && psql -v ON_ERROR_STOP=1 -Atc \"SELECT 1 FROM pg_database WHERE datname='$DATABASE_NAME';\"")" = "1" ]; then - records="$(su "$POSTGRES_USER" -c "cd / && psql -v ON_ERROR_STOP=1 -Atc 'SELECT COUNT(*) FROM $DATABASE_NAME.zerver_message;' $DATABASE_USER")" + records="$(su "$POSTGRES_USER" -c "cd / && psql -v ON_ERROR_STOP=1 -Atc 'SELECT COUNT(*) FROM $DATABASE_NAME.zerver_message;' $DATABASE_USER" || echo 0)" if [ "$records" -gt 200 ]; then set +x echo "WARNING: This will delete your Zulip database which currently contains $records messages."