Skip to content

Commit

Permalink
Ajoute un script qui copie la BDD de demo dans les review apps (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic authored Feb 10, 2025
1 parent 5d0755d commit 1ecb3b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Empty file added .heroku/ensure-directory
Empty file.
5 changes: 4 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
{
"plan": "postgresql:postgresql-sandbox"
}
]
],
"scripts": {
"postdeploy": "bash scripts/copy-scalingo-review-app-db.sh"
}
}
25 changes: 25 additions & 0 deletions scripts/copy-scalingo-review-app-db.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1ecb3b7

Please sign in to comment.