Skip to main content

How to use Object Group Hooks

info

This feature is only available when SOLE's LIFECYCLE_ACTION is set to AGGREGATE.

info

Hooks support key pair authentication and use the same authentication mode, variables, and credentials as SOLE. For more information, see the SOLE key pair authentication guide on how to implement key pair authentication for your organization.

SOLE supports the usage of pre- and post-Hooks. Hooks perform actions before and after lifecycle management of the respective #resource-group-hooks.

The pre- and post-hooks are executed for each run of SOLE.

SOLE has 4 different object group hierarchies:

  • Account-Level
  • Databases
  • Database-Level
  • Grants

Account-Level and Databases belong to the same group as per Snowflake. In SOLE they are executed separately so that databases can be executed by themselves. For hooks though, they are treated as a single group.

Each group has pre- and post-hooks. This allows you to define setup and teardown actions for each group for more control over the lifecycle of objects.

The execution per object group is illustrated below:

Execution flow of pre- and post-hooks for each object group __shadow__

caution

Hooks do not support Object name resolution and therefore always need to be fully qualified (database.schema.table/view). You can use template rendering to inject the name of the current database with {{ env.DATAOPS_DATABASE }} though.

Example

Hooks can be defined in any existing or new YAML file that is parsed by SOLE, typically any file in the directory specified in the parameter CONFIGURATION_DIR.

account_level_hooks:
pre_hooks:
- command: "ALTER ACCOUNT SET RESOURCE_MONITOR = USAGE_MONITOR;"
environment: snowflake
post_hooks:
- command: "$CI_PROJECT_DIR/dataops/sole_hooks/account_level_post_hook.sql"
environment: snowflake
- command: whoami
environment: bash

database_level_hooks:
post_hooks:
- command: "CALL add_table_to_share('SHAREFOO','DATAOPS_DEMO5_DEV','AW_PERSON','ADDRESS')"
environment: snowflake

grants_hooks:
pre_hooks:
- command: "$CI_PROJECT_DIR/dataops/sole_hooks/grant_pre_hook.sql"
environment: snowflake
post_hooks:
- command: "$CI_PROJECT_DIR/dataops/sole_hooks/grant_post_hook.sql"
environment: snowflake