-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/snowflake #9
Draft
jimmysteinmetz
wants to merge
2
commits into
main
Choose a base branch
from
feature/snowflake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Snowflake Utilities | ||
This repo assumes you have an instance of Snowflake available to you with ACCOUNTADMIN access. If you don't yet have an account, you can start with a free trial [here](https://signup.snowflake.com/). If you already have an account but not ACCOUNTADMIN access, you'll need to reach out to your Snowflake administrator. | ||
|
||
This deployment is using an instance of Snowflake deployed on Google Cloud Platform. This process can be completed on other cloud providers' Snowflake accounts, but will require a substantial amount of adaptation for the use of Snowpipe from bucket storage, and minor tweaks elsewhere in the code. We'll do our best to call out when these changes may occur. | ||
|
||
You may also want to have the SnowSQL Client installed if you plan to interact with your database via the command line. Instructions can be found [here](https://docs.snowflake.com/en/user-guide/getting-started-tutorial-prerequisites.html#snowsql-installation) | ||
|
||
## Intro | ||
|
||
Contains documentation and scripts used to create and administer Snowflake databases, warehouses, tables, users, roles, pipes, and other objects either via [SnowSQL (CLI Client)](https://docs.snowflake.com/en/user-guide/snowsql.html) or through the Snowflake Web UI | ||
|
||
## Scripts | ||
Scripts to be used via SnowSQL to execute functions, manipulate data, etc. | ||
|
||
## Queries | ||
Raw SQL Queries to be used either through the Web UI or using the CLI | ||
|
||
### DDL | ||
Queries used to create database infrastructure, roles, a user, and grant appropriate permissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Creating the initial Snowflake database to store ingested data from a Google Cloud Bucket | ||
|
||
USE ROLE SYSADMIN // or a role which is granted the appropriate permissions to create database, schema, and warehouse objects | ||
// TODO: create a role which is limited to only the exact permissions needed to execute this | ||
|
||
CREATE DATABASE NC_CAMPAIGN_FINANCE; | ||
CREATE SCHEMA NCCF; | ||
CREATE WAREHOUSE NCCF_DEV_WH | ||
WITH WAREHOUSE_SIZE = 'XSMALL' | ||
WAREHOUSE_TYPE = 'STANDARD' | ||
AUTO_SUSPEND = 60 | ||
AUTO_RESUME = TRUE; | ||
|
||
|
||
USE ROLE SECURITYADMIN; // or a role which is granted the appropriate permissions to grant permissions | ||
// TODO: limit this to just permissions required for these exact functions | ||
|
||
CREATE ROLE NCCF_DEV; | ||
GRANT ALL PRIVILEGES ON DATABASE NC_CAMPAIGN_FINANCE TO NCCF_DEV; | ||
GRANT ALL PRIVILEGES ON SCHEMA NC_CAMPAIGN_FINANCE.NCCF TO NCCF_DEV; | ||
GRANT ALL PRIVILEGES ON WAREHOUSE NCCF_DEV_WH to NCCF_DEV; | ||
GRANT ALL PRIVILEGES ON FUTURE SCHEMAS IN DATABASE NC_CAMPAIGN_FINANCE TO NCCF_DEV; | ||
GRANT ALL PRIVILEGES ON FUTURE TABLES IN SCHEMA NC_CAMPAIGN_FINANCE.NCCF to NCCF_DEV; | ||
GRANT ALL PRIVILEGES ON FUTURE VIEWS IN SCHEMA NC_CAMPAIGN_FINANCE.NCCF to NCCF_DEV; | ||
|
||
GRANT ROLE NCCF_DEV to USER JIMMY; # add your username | ||
|
||
USE ROLE USERADMIN; | ||
|
||
CREATE USER NCCF_SVC PASSWORD = 'insert-really-good-password-here' DEFAULT_ROLE = "NCCF_DEV" DEFAULT_WAREHOUSE = 'NCCF_DEV_WH' DEFAULT_NAMESPACE = 'NC_CAMPAIGN_FINANCE.NCCF' MUST_CHANGE_PASSWORD = TRUE; | ||
|
||
USE ROLE SECURITYADMIN; | ||
GRANT ROLE "NCCF_DEV" to USER NCCF_SVC; |
31 changes: 31 additions & 0 deletions
31
packages/snowflake/queries/ddl/CREATE_INGESTED_TRANSACTIONS_TABLE.SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
USE DATABASE NC_CAMPAIGN_FINANCE; | ||
USE SCHEMA NCCF; | ||
USE ROLE NCCF_DEV; | ||
USE WAREHOUSE NCCF_DEV_WH; | ||
|
||
CREATE OR ALTER TABLE INGESTED_TRANSACTIONS ( | ||
NAME VARCHAR, | ||
STREET_LINE_1 VARCHAR, | ||
STREET_LINE_2 VARCHAR, | ||
CITY VARCHAR, | ||
STATE VARCHAR, | ||
ZIP VARCHAR, | ||
PROFESSION_JOB_TITLE VARCHAR, | ||
EMPLOYERS_NAME_SPECIFIC_FIELD VARCHAR, | ||
TRANSACTION_TYPE VARCHAR(5), | ||
COMMITTEE_NAME VARCHAR, | ||
COMMITTEE_SBOE_ID VARCHAR, | ||
COMMITTEE_STREET_1 VARCHAR, | ||
COMMITTEE_STREET_2 VARCHAR, | ||
COMMITTEE_CITY VARCHAR, | ||
COMMITTEE_STATE VARCHAR, | ||
COMMITTEE_ZIP_CODE VARCHAR, | ||
REPORT_NAME VARCHAR, | ||
DATE_OCCURED VARCHAR, | ||
ACCOUNT_CODE VARCHAR, | ||
AMOUNT VARCHAR, | ||
FORM_OF_PAYMENT VARCHAR, | ||
PURPOSE VARCHAR, | ||
CANDIDATE_REFERENDUM_NAME VARCHAR, | ||
DECLARATION VARCHAR | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
snowsql -a vx50048.us-central1.gcp -u nccf_svc -d nc_campaign_finance_dev -s nccf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably contain placeholders instead. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is specific to the north carolina project we should probably move this as a sub-package of north-carolina