From 1ecb3b7f86928637f4f923b6861c561bae1a166c Mon Sep 17 00:00:00 2001 From: niladic Date: Mon, 10 Feb 2025 16:20:21 +0100 Subject: [PATCH] Ajoute un script qui copie la BDD de demo dans les review apps (#2183) --- .heroku/ensure-directory | 0 app.json | 5 ++++- scripts/copy-scalingo-review-app-db.sh | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .heroku/ensure-directory create mode 100644 scripts/copy-scalingo-review-app-db.sh diff --git a/.heroku/ensure-directory b/.heroku/ensure-directory new file mode 100644 index 000000000..e69de29bb diff --git a/app.json b/app.json index b3187bc64..161e97586 100644 --- a/app.json +++ b/app.json @@ -23,5 +23,8 @@ { "plan": "postgresql:postgresql-sandbox" } - ] + ], + "scripts": { + "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 new file mode 100644 index 000000000..bc502bf3b --- /dev/null +++ b/scripts/copy-scalingo-review-app-db.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +echo "Running Scalingo review app DB copy script" + +if [ "$IS_REVIEW_APP" = "true" ]; then + dbclient-fetcher pgsql 15 + + echo "Copying review app db" + + 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" -gt 0 ] 2>/dev/null; then + echo "Table 'user' has $USER_COUNT rows. Doing nothing." + else + 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}" + + fi + +else + echo "Not a review app - skipping database copy" +fi