The problem I’m having
I’d like to execute a particular model in a macro. Something along this way:
{%- macro foobar(model_name, target_name) -%}
dbt run -s {{ model_name }} -t {{ target_name }}
{%- endmacro -%}
The context of why I’m trying to do this
We want to help others running models safely in a dev schema. However, some models have many large upstream dependencies. Therefore, I am writing a macro which, given a model name I want to refresh, copies all production tables and views, basically all upstream models, into a dev schema.
I am able to get all the upstream models. Copying tables
is also straightforward (create table dev_john.big_table as select * from prod_schema.big_table
), however there is no such thing for a view
.
Therefore, I am looking for a way to run models which are views from macro.
(I know about --defer
and we use it, but we do not want to use it in this case as it sometimes leads to annoying transaction blocks and problems)
What I’ve already tried
The only thing I came up is to just create view dev_john.my_view as select * from prod_schema.my_view with no schema binding
. But I’d rather to do dbt run -s my_view -t dev_john
to really have no dependencies between prod and dev.
Any ideas would be greatly appreciated.
Thank you.