diff --git a/Makefile b/Makefile index d3ef786..2d0b669 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,6 @@ $(build)/workflow-runs.html: $(build)/workflow-runs.json $(build)/workflow-runs. ./generate.js > $@ $(build)/workflow-runs.json: $(build)/%.json: %.sql | $(build) - ./steampipe-psql -c '\dn' -c 'show search_path' ./steampipe-psql --quiet --no-align --tuples-only --set=ON_ERROR_STOP= < $< > $@ $(build)/workflow-runs.%: workflow-runs.% | $(build) diff --git a/steampipe-psql b/steampipe-psql index e9ab487..d0f0584 100755 --- a/steampipe-psql +++ b/steampipe-psql @@ -44,6 +44,13 @@ main() { ' EXIT fi + # Steampipe is sometimes slow about registering schemas for plugins and if + # we try to run our query before they exist it'll fail. + while ! schemas-available net github; do + echo "Waiting for schemas to become available…" >&2 + sleep 1 + done + # No exec because of our trap above psql "$@" } @@ -59,4 +66,26 @@ steampipe-service-available() { nc -zw3 "$PGHOST" "$PGPORT" &>/dev/null } +schemas-available() { + local -a psql=(psql --quiet --no-psqlrc --no-align --tuples-only) + local -a vars + + local i=0 + for schema; do + var="schema$((i++))" + psql+=("--set=$var=$schema") + vars+=(":'$var'") + done + + local query="select count(*) from pg_catalog.pg_namespace where nspname in ($(join , "${vars[@]}"))" + + [[ "$("${psql[@]}" <<<"$query")" -eq ${#vars[@]} ]] +} + +join() { + local IFS="$1" + shift + echo "$*" +} + main "$@"