Skip to content

Commit

Permalink
list_modified_downstream.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRobin committed Oct 23, 2024
1 parent 3cc0c56 commit c97c6cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/dbt_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
- name: dbt seed
run: "dbt seed $PROFILE --select @state:modified --exclude tag:prod_exclude tag:remove --state . --project-dir ${PROJECT_DIR}"

- name: list downstream models
run: "./scripts/list_modified_downstream.sh"

- name: dbt run initial model(s)
run: "dbt -x run $PROFILE --select state:modified --exclude tag:prod_exclude tag:remove --defer --state . --project-dir ${PROJECT_DIR}"

Expand Down
26 changes: 26 additions & 0 deletions scripts/list_modified_downstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Check if required environment variables are set
if [ -z "$PROFILE" ] || [ -z "$PROJECT_DIR" ]; then
echo "Error: PROFILE and PROJECT_DIR environment variables must be set"
echo "Example usage:"
echo "PROFILE=myprofile PROJECT_DIR=/path/to/project ./script.sh"
exit 1
fi

# Run dbt command and store output
dbt_output=$(dbt ls $PROFILE \
--resource-type model \
--select state:modified+ \
--output json \
--output-keys alias schema config \
--state . \
--project-dir $PROJECT_DIR)

# 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)"' | \
sort | \
while read -r materialization schema alias; do
echo "[$materialization] - $schema.$alias"
done

0 comments on commit c97c6cd

Please sign in to comment.