Tips and Tricks about working with dbt

Nice! The one trick I really like involves using some bash magic to run all of the changed files on a branch.

Snippet:

dbt run --models $(git diff --name-only | grep '\.sql$' | awk -F '/' '{ print $NF }' | sed 's/\.sql$/+/g')

You can save this in your .bashrc with a function, eg:

function dbt_run_changed() {
    children=$1
    models=$(git diff --name-only | grep '\.sql$' | awk -F '/' '{ print $NF }' | sed "s/\.sql$/${children}/g" | tr '\n' ' ')
    echo "Running models: ${models}"
    dbt run --models $models
}

This function takes an optional argument, +, that will also run the children of the changed models!

Usage:

$ dbt_run_changed
$ dbt_run_changed +
10 Likes