Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic committed Feb 10, 2025
1 parent bacd9ea commit bd24a37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
postdeploy: bash scripts/copy-scalingo-review-app-db.sh
14 changes: 12 additions & 2 deletions scripts/copy-scalingo-review-app-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bd24a37

Please sign in to comment.