begin;
/* Set variables for script. Replace the values in {brackets} with your own values */
set var_user = '{user}'; -- Username for the Sawmills service account
set var_password = '{password}'; -- Secure password for the service account
set var_role = '{role}'; -- Name of the role to be created (e.g., 'SAWMILLS_ROLE')
set var_database = '{database}'; -- Database where telemetry will be stored
set var_warehouse = '{warehouse}'; -- Warehouse to be used for data processing
/* Create and configure Sawmills role and user */
use role securityadmin; -- Switch to security admin to manage roles and users
create role if not exists identifier($var_role);
grant role identifier($var_role) to role SYSADMIN;
create user if not exists identifier($var_user)
password = $var_password
default_role = $var_role
default_warehouse = $var_warehouse;
grant role identifier($var_role) to user identifier($var_user);
/* Grant necessary permissions */
use role accountadmin; -- Switch to account admin for granting warehouse access
grant USAGE -- Allow the role to use the warehouse
on warehouse identifier($var_warehouse)
to role identifier($var_role);
grant CREATE SCHEMA, MONITOR, USAGE -- Grant database-level permissions
on database identifier($var_database)
to role identifier($var_role);
commit;