sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Feat: Make this_env and views available in macros of before after all

Open themisvaltinos opened this issue 1 year ago • 0 comments

This update adds the this_env variable in the macros for before all after all statements as well as views which provides all the views of the virtual layer to be able to easily for example grant rights on the views:

@macro()
def grant_select_privileges(evaluator):
    if evaluator.views:
        return [
            f"GRANT SELECT ON VIEW {view_name} /* sqlglot.meta replace=false */ TO ROLE admin_role;"
            for view_name in evaluator.views
        ]

By including the comment /* sqlglot.meta replace=false */, you ensure that the evaluator does not replace the view name with the physical table name.

themisvaltinos avatar May 01 '25 16:05 themisvaltinos