Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRobin committed Oct 23, 2024
1 parent 756815a commit 97c6d81
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion scripts/list_modified_downstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@ if [ -z "$PROFILE" ] || [ -z "$PROJECT_DIR" ]; then
fi

# Run dbt command and store output
# Using grep to get only the JSON line (assuming it's the last line)
dbt_output=$(dbt ls $PROFILE \
--resource-type model \
--select state:modified+ \
--output json \
--output-keys alias schema config \
--state . \
--project-dir $PROJECT_DIR)
--project-dir $PROJECT_DIR | tail -n 1)

# For debugging, uncomment these lines:
echo "Raw output:"
echo "$dbt_output"

# Check if output is empty or invalid JSON
if [ -z "$dbt_output" ] || [ "$dbt_output" = "[]" ]; then
echo "No modified models found"
exit 0
fi

# Check if the output is valid JSON
if ! echo "$dbt_output" | jq empty 2>/dev/null; then
echo "Invalid JSON output from dbt"
exit 1
fi

# Use jq to parse the JSON and format the output, then sort using sort command
echo "$dbt_output" | \
jq -r '.[] | "\(.config.materialized // "view") \(.schema) \(.alias)"' | \
Expand Down

0 comments on commit 97c6d81

Please sign in to comment.