1. Select Snowflake in the Create Sync page in Stacksync.
2. Copy the user public key for next steps
3. Find the credentials for your Snowflake instance.
Note the database name, schema name and the account identifier.
Account Identifier uniquely identifies a Snowflake account within your organization. It is a combination of your organization name and account name. It can be found in the Snowflake web interface.
Copy the following script which will create a new Stacksync role, user with the necessary permissions.
Paste the copied public key in create user section, if you don't want to create user, then you can set the rsa_public_key for existing user ( user type should be 'service')
-- create the variables for user and role details
set role_name = 'STACKSYNC_ROLE';
set user_name = 'STACKSYNC_USER'; -- enter the username
set warehouse_name = 'COMPUTE_WH'; -- enter the warehouse you want to use
set database_name = 'STACKSYNC_TEST';
set user_type = 'service'; -- set to service user type.
-- change role to security admin to create user and role
use role securityadmin;
-- create the Stacksync Role
create role if not exists identifier($role_name);
grant role identifier($role_name) to role SYSADMIN;
-- create a user for Stacksync
create user if not exists identifier($user_name)
-- copy paste public key from stacksync.
rsa_public_key = '-----BEGIN PUBLIC KEY-----
MIIBIjANBg......
-----END PUBLIC KEY-----'
type = $user_type
default_role = $role_name
default_warehouse = $warehouse_name;
-- grant Stacksync role to the new user
grant role identifier($role_name) to user identifier($user_name);
-- change role to accountadmin to grant permissions to the Stacksync Role
use role accountadmin;
-- grant Stacksync role access to warehouse
grant usage on warehouse identifier($warehouse_name) to role identifier($role_name);
-- grant Stacksync role access to database and create schemas
grant usage on database identifier($database_name) to role identifier($role_name);
grant create schema on database identifier($database_name) to role identifier($role_name);
-- select the database
use database identifier($database_name);
-- grant previlages to the all the schemas you want to sync (This example is for the PUBLIC schema)
-- Create tables and stream previlages.
grant usage on schema PUBLIC to role identifier($role_name);
grant create table on schema PUBLIC to role identifier($role_name);
grant create stream on schema PUBLIC to role identifier($role_name);
grant select on all tables in schema PUBLIC to role identifier($role_name);
grant select on future tables in schema PUBLIC to role identifier($role_name); -- (optional, for future tables)
-- repeat the steps above for all Schemas you want to sync.
5. Enter the credentials for Snowflake and Click Authorize App.