Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow base model creation to take multiple tables as arguments #225

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ This bash script when executed from your local IDE will create model files in yo
2. Copy the macro into a statement tab into your local IDE, and run your code

```bash
source dbt_packages/codegen/bash_scripts/base_model_creation.sh "source_name" ["this-table","that-table"]
source dbt_packages/codegen/bash_scripts/base_model_creation.sh source_name table-1 table-2 table-3 ...
```

## generate_model_yaml ([source](macros/generate_model_yaml.sql))
Expand Down
14 changes: 12 additions & 2 deletions bash_scripts/base_model_creation.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash

echo "" > models/stg_$1__$2.sql
# Check if at least two arguments are provided (source_name and at least one table_name)
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <source_name> <table_name1> [table_name2 ... table_nameN]"
exit 1
fi

dbt --quiet run-operation codegen.generate_base_model --args '{"source_name": "'$1'", "table_name": "'$2'"}' | tail -n +3 >> models/stg_$1__$2.sql
SOURCE_NAME=$1
shift # Shift to leave only table names in "$@"

for TABLE_NAME in "$@"; do
dbt --quiet run-operation codegen.generate_base_model --args '{"source_name": "'$SOURCE_NAME'", "table_name": "'$TABLE_NAME'"}' | tail -n +3 >> models/stg_${SOURCE_NAME}__${TABLE_NAME}.sql
echo "Generated model for table: $TABLE_NAME"
done
Loading