Skip to content

Commit

Permalink
add use_role option
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklausroach committed Apr 9, 2024
1 parent 6dcd59a commit da5203b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
dist/
*.egg-info/
build/
**/__pycache__/
**/__pycache__/
sprocketship/example/target
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "sprocketship"
version = "0.4.2"
version = "0.5.0"
authors = [
{ name="Nicklaus Roach", email="nicklausroach@gmail.com" },
]
Expand Down
6 changes: 5 additions & 1 deletion sprocketship/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def liftoff(dir, show):
rendered_proc = create_javascript_stored_procedure(
**proc, **{"project_dir": dir}
)
if 'use_role' in proc.keys():
con.cursor().execute(f"USE ROLE {proc['use_role'].upper()}")
else:
con.cursor().execute(f"USE ROLE {data['snowflake']['role']}")
con.cursor().execute(rendered_proc)
msg = click.style(f"{proc['name']} ", fg="green", bold=True)
msg += click.style(f"launched into schema ", fg="white", bold=True)
Expand Down Expand Up @@ -80,7 +84,7 @@ def build(dir, target):
rendered_proc = create_javascript_stored_procedure(
**proc, **{"project_dir": dir}
)
with open(os.path.join(dir, target, proc["name"] + ".sql"), "+a") as f:
with open(os.path.join(dir, target, proc["name"] + ".sql"), "w") as f:
f.write(rendered_proc)
msg = click.style(f"{proc['name']} ", fg="green", bold=True)
msg += click.style(f"successfully built", fg="white", bold=True)
Expand Down
1 change: 1 addition & 0 deletions sprocketship/example/.sprocketship.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ procedures:
database: !env_var SNOWFLAKE_DATABASE
schema: !env_var SNOWFLAKE_SCHEMA
language: javascript
use_role: data_engineer
execute_as: owner
args:
- name: database_name
Expand Down
2 changes: 1 addition & 1 deletion sprocketship/templates/javascript.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ $$

{{procedure_definition}}

$$
$$;

0 comments on commit da5203b

Please sign in to comment.