From 4d52431c95eda467470fa11372bc8c53c0dc71e6 Mon Sep 17 00:00:00 2001 From: Scott Weldon Date: Mon, 25 Dec 2023 10:27:54 -0800 Subject: [PATCH] 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. --- root/entrypoint.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/root/entrypoint.sh b/root/entrypoint.sh index f05c506..9aaf34a 100755 --- a/root/entrypoint.sh +++ b/root/entrypoint.sh @@ -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."