# -*- mode: shell-script -*- sql() { local dbname="$1" ( DBNAME="$(relation:get "$SERVICE_NAME":postgres-database dbname)" || return 1 ts=$(service:traverse "$SERVICE_NAME":"postgres-database") || return 1 export SERVICE_NAME="$ts" export SERVICE_DATASTORE="$DATASTORE/$SERVICE_NAME" target_charm=$(get_service_charm "$ts") || return 1 target_charm_path=$(charm.get_dir "$target_charm") || return 1 set +e . "$target_charm_path/lib/common" set -e metadata_service_def=$(_get_service_metadata "$ts") || return 1 type=$(e "$metadata_service_def" | yq -r '.type') || true if [[ "$type" != "stub" ]]; then DOCKER_BASE_IMAGE=$(service_ensure_image_ready "$SERVICE_NAME") || return 1 export DOCKER_BASE_IMAGE ensure_db_docker_running fi ddb "${dbname:-$DBNAME}" ) }