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.

30 lines
927 B

  1. # -*- mode: shell-script -*-
  2. sql() {
  3. local dbname="$1"
  4. (
  5. DBNAME="$(relation:get "$SERVICE_NAME":postgres-database dbname)" || return 1
  6. ts=$(service:traverse "$SERVICE_NAME":"postgres-database") || return 1
  7. export SERVICE_NAME="$ts"
  8. export SERVICE_DATASTORE="$DATASTORE/$SERVICE_NAME"
  9. target_charm=$(get_service_charm "$ts") || return 1
  10. target_charm_path=$(charm.get_dir "$target_charm") || return 1
  11. set +e
  12. . "$target_charm_path/lib/common"
  13. set -e
  14. metadata_service_def=$(_get_service_metadata "$ts") || return 1
  15. type=$(e "$metadata_service_def" | yq -r '.type') || true
  16. if [[ "$type" != "stub" ]]; then
  17. DOCKER_BASE_IMAGE=$(service_ensure_image_ready "$SERVICE_NAME") || return 1
  18. export DOCKER_BASE_IMAGE
  19. ensure_db_docker_running
  20. fi
  21. ddb "${dbname:-$DBNAME}"
  22. )
  23. }