sqlmesh
sqlmesh copied to clipboard
Feat: Make this_env and views available in macros of before after all
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.