Check if tables exist before installing

This works better than checking just the database, because it could be
that an empty database has already been created (with e.g. Docker
Compose).

TABLES_EXIST should be empty if no tables, or will return a 1
for *each* table that exists.
This commit is contained in:
Scott Weldon
2023-12-25 10:27:54 -08:00
parent 64d2a60888
commit 4d52431c95

View File

@ -76,6 +76,12 @@ provisioner() {
echo "Configuring the Postgres database ..."
psql -q -h "${SYMFONY__ENV__DATABASE_HOST}" -p "${SYMFONY__ENV__DATABASE_PORT}" -U "${POSTGRES_USER}" \
-c "CREATE DATABASE ${SYMFONY__ENV__DATABASE_NAME};"
fi
TABLES_EXIST="$(psql -qAt -h "${SYMFONY__ENV__DATABASE_HOST}" -p "${SYMFONY__ENV__DATABASE_PORT}" -U "${POSTGRES_USER}" \
-c "SELECT 1 FROM pg_catalog.pg_tables WHERE schemaname = 'public';")"
if [ "$TABLES_EXIST" == "" ]; then
echo "Installing Wallabag ..."
install_wallabag
else
echo "WARN: Postgres database is already configured. Remove the environment variable with root password."