From bd24a37408916261c6f4e456899f4500982f8c7c Mon Sep 17 00:00:00 2001 From: niladic Date: Mon, 10 Feb 2025 15:25:52 +0100 Subject: [PATCH] fix --- Procfile | 1 + scripts/copy-scalingo-review-app-db.sh | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 00000000..c2cbbf28 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +postdeploy: bash scripts/copy-scalingo-review-app-db.sh diff --git a/scripts/copy-scalingo-review-app-db.sh b/scripts/copy-scalingo-review-app-db.sh index 0dac9a39..918b2629 100644 --- a/scripts/copy-scalingo-review-app-db.sh +++ b/scripts/copy-scalingo-review-app-db.sh @@ -7,9 +7,19 @@ if [ "$IS_REVIEW_APP" = "true" ]; then echo "Copying review app db" - /app/bin/pg_dump --clean --if-exists --format c --dbname "${PARENT_APP_DATABASE_URL}" --no-owner --no-privileges --no-comments --exclude-schema 'information_schema' --exclude-schema '^pg_*' | /app/bin/pg_restore --clean --if-exists --no-owner --no-privileges --no-comments --dbname "${SCALINGO_POSTGRESQL_URL}" + echo "Checking number of rows in 'user' table" + + USER_COUNT=$(/app/bin/psql "${SCALINGO_POSTGRESQL_URL}" -A -t -c 'SELECT COUNT(*) FROM "user";') + + if [ "$USER_COUNT" = "0" ]; then + echo "Table 'user' has $USER_COUNT rows. Copying parent app db to review app db." + + /app/bin/pg_dump --clean --if-exists --format c --dbname "${PARENT_APP_DATABASE_URL}" --no-owner --no-privileges --no-comments --exclude-schema 'information_schema' --exclude-schema '^pg_*' | /app/bin/pg_restore --clean --if-exists --no-owner --no-privileges --no-comments --dbname "${SCALINGO_POSTGRESQL_URL}" + + else + echo "Table 'user' has $USER_COUNT rows. Doing nothing." + fi - echo "Done" else echo "Not a review app - skipping database copy" fi