Skip to content

Commit

Permalink
wip! debugging3
Browse files Browse the repository at this point in the history
  • Loading branch information
tsibley committed Feb 14, 2024
1 parent 0d4eff5 commit ac6eedc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions steampipe-psql
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
}
Expand All @@ -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 "$@"

0 comments on commit ac6eedc

Please sign in to comment.