You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/macros/macro_variables.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,4 +140,5 @@ SQLMesh provides additional predefined variables used to modify model behavior b
140
140
The following variables are also available in [`before_all` and `after_all` statements](../../guides/configuration.md#before_all-and-after_all-statements), as well as in macros invoked within them.
141
141
142
142
* @this_env - A string value containing the name of the current [environment](../environments.md).
143
-
*@schemas - A list of the schema names of the [virtual layer](../../concepts/glossary.md#virtual-layer) of the current environment.
143
+
*@schemas - A list of the schema names of the [virtual layer](../../concepts/glossary.md#virtual-layer) of the current environment.
144
+
*@views - A list of the view names of the [virtual layer](../../concepts/glossary.md#virtual-layer) of the current environment.
Copy file name to clipboardExpand all lines: docs/guides/configuration.md
+9-18Lines changed: 9 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -675,7 +675,7 @@ Configuration for a connection used to run unit tests. An in-memory DuckDB datab
675
675
676
676
### Scheduler
677
677
678
-
Identifies which scheduler backend to use. The scheduler backend is used both for storing metadata and for executing [plans](../concepts/plans.md). By default, the scheduler type is set to `builtin`, which uses the existing SQL engine to store metadata.
678
+
Identifies which scheduler backend to use. The scheduler backend is used both for storing metadata and for executing [plans](../concepts/plans.md). By default, the scheduler type is set to `builtin`, which uses the existing SQL engine to store metadata.
679
679
680
680
These options are in the [scheduler](../reference/configuration.md#scheduler) section of the configuration reference page.
681
681
@@ -1019,20 +1019,18 @@ For example, rather than using an `on_virtual_update` statement in each model to
1019
1019
1020
1020
```python linenums="1"
1021
1021
from sqlmesh.core.macros import macro
1022
-
from sqlmesh.core.snapshot.definition import to_view_mapping
f"GRANT SELECT ON VIEW {view_name} TO ROLE admin_role;"
1032
-
for view_name in mapping.values()
1027
+
f"GRANT SELECT ON VIEW {view_name} /* sqlglot.meta replace=false */ TO ROLE admin_role;"
1028
+
for view_name in evaluator.views
1033
1029
]
1034
1030
```
1035
1031
1032
+
By including the comment `/* sqlglot.meta replace=false */`, you further ensure that the evaluator does not replace the view name with the physical table name during rendering.
1033
+
1036
1034
##### Example: Granting Schema Privileges
1037
1035
1038
1036
Similarly, you can define a macro to grant schema usage privileges and, as demonstrated in the configuration above, using `this_env` macro conditionally execute it only in the production environment.
if evaluator.this_env == "prod" and evaluator.schemas:
1053
1044
return [
1054
1045
f"GRANT USAGE ON SCHEMA {schema} TO admin_role;"
1055
-
for schema in schemas
1046
+
for schema in evaluator.schemas
1056
1047
]
1057
1048
```
1058
1049
1059
-
As demonstrated in these examples, the `environment_naming_info` is available within the macro evaluator for macros invoked within the `before_all` and `after_all` statements. Additionally, the macro `this_env` provides access to the current environment name, which can be helpful for more advanced use cases that require fine-grained control over their behaviour.
1050
+
As demonstrated in these examples, the `schemas` and `views` are available within the macro evaluator for macros invoked within the `before_all` and `after_all` statements. Additionally, the macro `this_env` provides access to the current environment name, which can be helpful for more advanced use cases that require fine-grained control over their behaviour.
0 commit comments