on-run-start & on-run-end
dbt_project.yml
on-run-start: sql-statement | [sql-statement]
on-run-end: sql-statement | [sql-statement]
Definitionβ
A SQL statement (or list of SQL statements) to be run at the start, or end, of the following commands:
dbt run
dbt test
dbt seed
dbt snapshot
dbt build
dbt compile
dbt docs generate
on-run-start
and on-run-end
hooks can also call macros that return SQL statements
Usage notesβ
- The
on-run-end
hook has additional jinja variables available in the context β check out the docs.
Examplesβ
Grant privileges at the end of a runβ
dbt_project.yml
on-run-end: "grant select on all tables in schema {{ target.schema }} group transformer"
Grant multiple privileges at the end of a runβ
dbt_project.yml
on-run-end:
- "grant usage on schema {{ target.schema }} to group reporter"
- "grant select on all tables in schema {{ target.schema }} group reporter"
Grant privileges on all schemas that dbt uses at the end of a runβ
This leverages the schemas variable that is only available in an on-run-end
hook.
dbt_project.yml
on-run-end:
- "{% for schema in schemas %}grant usage on schema {{ schema }} to group reporter; {% endfor %}"
Call a macro to grant privilegesβ
dbt_project.yml
on-run-end: "{{ grant_select(schemas) }}"
Additional examplesβ
We've compiled some more in-depth examples here.