Programmatic config
Last updated
Last updated
It is possible to extend and modify SnowDDL programmatically using pure Python.
A few examples of real business use cases which can be implemented with this technique:
Get list of users dynamically from single sign-on data provider;
Generate a view for each table in specific schemas;
Generate masking policy for each table containing columns named "email" and "phone";
Skip certain types of objects in DEV environment;
There are not restrictions. Any external data source and any Python package can be used.
Create a standard directory with . You may optionally fill it with YAML files.
Create a sub-directory with name __custom
(starting with two underscores) in config directory.
Place one or more python modules (.py
files) in __custom
sub-directory.
During SnowDDL execution YAML configs are resolved first. After that Python modules are resolved one-by-one in alphanumeric order.
It is highly recommended to start module names with zero-padded numbers to make sure you have a precise control of resolution order, for example: 01_foo.py
, 02_bar.py
, 03_baz.py
.
Each module should have a function with name handler
, which accepts instance of as a single argument. This function does not return anything.
In handler
function you may build objects representing the desired state of objects in Snowflake, and use methods .add_blueprint()
and .remove_blueprint()
to manipulate the collection of blueprints.
You may access existing using methods .get_blueprints_by_type()
and .get_blueprints_by_type_and_pattern()
.
Example of Python module adding a few custom tables:
Example of Python module which scans current config for custom tables and generates a consolidated view dynamically:
Complete example of config with __custom
sub-directory: