The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

57 lines
1.9 KiB

  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
  4. #
  5. #
  6. # Drop the various temporary databases that sometimes get left around by the tests
  7. # Do not run this command while tests are running
  8. #
  9. # Usage:
  10. #
  11. # cleanup_bubble_databases [db-match] [fg]
  12. #
  13. # db-match all databases that contain this string will be dropped. default is "bubble_"
  14. # foreground normally a forked shell is used for each "dropdb" command; if the last argument is "fg" then we'll use the current shell
  15. #
  16. # Note: if you specify db-match "bubble", this would normally include the default bubble database, but it will be
  17. # specifically excluded by this script, to avoid dropping a real database with real data in it.
  18. #
  19. # To drop the "bubble" database, you must drop it directly with dropdb.
  20. #
  21. SCRIPT="${0}"
  22. SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd)
  23. DB_MATCH="${1:-bubble_}"
  24. DB_USER="$(whoami)"
  25. FORK_DROP=1
  26. if [[ "${2:-fork}" = "fg" ]] ; then
  27. FORK_DROP=0
  28. fi
  29. if [[ ${FORK_DROP} -eq 1 ]] ; then
  30. set -m
  31. fi
  32. DATABASE_COUNT="$(echo "select datname from pg_database" | psql -qt -U ${DB_USER} template1 | grep ${DB_MATCH} | wc -l | tr -d ' ')"
  33. if [[ ${DATABASE_COUNT} -gt 0 ]] ; then
  34. echo "Cleaning up ${DATABASE_COUNT} databases..."
  35. DATABASES="$(echo "select datname from pg_database" | psql -qt -U ${DB_USER} template1 | grep ${DB_MATCH} | tr -d ' ')"
  36. if [[ ! -z "${DATABASES}" ]] ; then
  37. for db in ${DATABASES} ; do
  38. if [[ "${db}" == "bubble" ]] ; then
  39. echo "Not dropping bubble default database"
  40. else
  41. if [[ "${FORK_DROP}" -eq 1 ]] ; then
  42. dropdb -U ${DB_USER} ${db} &
  43. else
  44. dropdb -U ${DB_USER} ${db} || echo "Error dropping database: ${db}"
  45. fi
  46. fi
  47. done
  48. fi
  49. else
  50. echo "No databases whose name contains \"${DB_MATCH}\" to clean up"
  51. fi