From 5d74dc44193c23f410d8e4ebce654f21267fcf3d Mon Sep 17 00:00:00 2001 From: jayknair Date: Sun, 31 Aug 2025 10:44:50 -0400 Subject: [PATCH] adding a helper function to set the environment variables before we run sample data loads --- avalanche/initialize_system/initialize_system.py | 11 ++++++++++- .../avalanche_executor_role.jinja.sql | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/avalanche/initialize_system/initialize_system.py b/avalanche/initialize_system/initialize_system.py index f87dd9b..544c0a3 100644 --- a/avalanche/initialize_system/initialize_system.py +++ b/avalanche/initialize_system/initialize_system.py @@ -129,7 +129,7 @@ def create_all_schema_objects(snowflake_conn: snowflake_connector_connection.Sno def get_avalanche_schema(config:dict) -> str: - """reads the config and gets the avalanche_schema valye""" + """reads the config and gets the avalanche_schema value""" avalanche_schema = config.get("avalanche_schema", None) if not avalanche_schema : raise KeyError("avalanche_schema key is missing in the config - check the `init_config.yaml` and config that entry exists and has valid schema name value") @@ -257,6 +257,14 @@ def parse_command_line_args(): "role": args.role } + +def set_environment_variables_based_on_config(avalanche_db: str, avalanche_schema: str): + """ Since the next step is going to emulate an actual avalanche setup - it needs some environment variables to be + set or it will use defaults . To avoid potential confusion we will set it based on the init_configs value""" + os.environ[ConnectionManager.AVALANCHE_SNOWFLAKE_DB_DATABASE] = avalanche_db + os.environ[ConnectionManager.AVALANCHE_SNOWFLAKE_DB_SCHEMA] = avalanche_schema + + def main(): command_line_args = parse_command_line_args() @@ -281,6 +289,7 @@ def main(): load_data_to_snowflake(df, conn, "DATATYPE_MAPPING_CONFIG") insert_default_datatype_mapping_group_config(snowflake_conn=conn) + set_environment_variables_based_on_config(avalanche_db=config["database"], avalanche_schema=avalanche_schema) initialize_sample_data(snowflake_conn=conn,avalanche_executor_role=config.get("avalanche_executor_role")) diff --git a/avalanche/initialize_system/templates/permission_assignments/avalanche_executor_role.jinja.sql b/avalanche/initialize_system/templates/permission_assignments/avalanche_executor_role.jinja.sql index 8d82be2..3705e9a 100644 --- a/avalanche/initialize_system/templates/permission_assignments/avalanche_executor_role.jinja.sql +++ b/avalanche/initialize_system/templates/permission_assignments/avalanche_executor_role.jinja.sql @@ -1,6 +1,7 @@ create role if not exists {{avalanche_executor_role}}; +grant usage on database {{database}} to role {{avalanche_executor_role}}; grant usage on schema {{avalanche_schema}} to role {{avalanche_executor_role}}; grant create function on schema {{avalanche_schema}} to role {{avalanche_executor_role}}; grant create procedure on schema {{avalanche_schema}} to role {{avalanche_executor_role}};