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

Add helper methods for setting pre-and post-hooks #1125

Closed
drewbanin opened this issue Nov 14, 2018 · 1 comment
Closed

Add helper methods for setting pre-and post-hooks #1125

drewbanin opened this issue Nov 14, 2018 · 1 comment
Labels
enhancement New feature or request

Comments

@drewbanin
Copy link
Contributor

Feature

Feature description

See also #558

Presently, in-model hook definitions need to be set in a {{ config() }} block. This isn't the most natural place for long-form SQL. Instead, dbt should provide a set of helper macros for setting pre- and post- hooks. For example:

{{ config(materialized='table') }}

{{ post_hook("grant select on {{ this }}" to db_reader") }}
{{ post_hook(some_complex_macro()} }}

This will also be a nice interface for inclusion in higher-level macros.

Who will this benefit?

Users with many model-specific hooks.

@drewbanin drewbanin added enhancement New feature or request estimate: 2 labels Nov 14, 2018
@jakebiesinger
Copy link

jakebiesinger commented Nov 19, 2018

IMHO, variables would probably handle this more easily and without work from you:

{% set post_hook %}
  {% for role in ['db_reader', 'db_writer'] %}
    grant select on {{ this }} to {{ role }};
  {% endfor %}
{% endset %}

{{ config({ 'materialized': 'table', 'post-hook': post_hook}) }}

Probably deserves an update to your documentation though, since folks may not know about multi-line set blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants