# orchard-analytics-dbt

# SETUP

- First, make a fork of the master repo located at https://github.com/theorchard/orchard-analytics-dbt.

- in a terminal window, navigate to a folder where you would like to save and type `git clone {git clone link found in forked repo}`

- `cd` into the folder you just created

- make sure to edit the '.env.shadow' file with all of your Snowflake credentials. Then rename this file to '.env'

- If you would like to use SSH authentication with DBT, its recommended to follow this (email systems to help with adding the public key to Snowflake): https://docs.snowflake.com/en/user-guide/python-connector-example.html#using-key-pair-authentication

- Install poetry (if not already installed) https://python-poetry.org/docs/#installation

- Poetry is a tool for dependency management / packaging in Python (also manages virtual environments)

- `poetry install` installs all the necessary requirements!

- `poetry shell` launches the virtual environment.

- **Note:** Poetry will not load env variables when activating the environment, run `source .env` to avoid any errors

- Basic notes about using dbt: Documentation: https://docs.getdbt.com/
  - DBT runs on the command line
  - To run a specific model, use the framework `dbt run --models model_name --profiles-dir ./profiles/sf_pswd_auth`
  - --profiles-dir tells DBT where to find your credentials.
  - **Note:** If you have Snowflake MFA enabled, you will have to manually authenticate (ie touch smartphone agree's) every time DBT opens a new Snowflake connection.
  - If you have SSH authentication enabled, run instead `--profiles-dir ./profiles/sf_ssh_auth`

- Run the command `dbt run --models test_pipenv --profiles-dir  ./profiles/sf_pswd_auth` in order to make sure everything was set up correctly

- You can see DBT running in the same terminal window, make sure everything passes with no errors

- Note: in order to generate a requirements.txt from poetry, run `poetry export -f requirements.txt --output requirements.txt`
