DBT Development and Production:
In this tutorial, we will guide you through setting up dbt Cloud with Snowflake. Along the way, we'll demonstrate how to configure both your development and production environments.
Video
Requirement
- At least a free Snowflake (trial account) and no complex security needs.
- At least a free DBT developer account and no complex security needs.
- A git repository. I suggest github.
Snowflake
First lets start in Snowflake by setting up some resources. We'll create one database, two warehouses and one new users using sysadmin role.
If your user is using MFA - Please enable token caching before uploading
If your planned development user is using MFA. Please enable token caching or else it will ask you for authentication everytime you run anything in dbt.
Development
Lets walk through the development environment setup in dbt.
Project
As soon on you login you'll be asked to start a project and give it a name.
We'll want to add our development environment connection to Snowflake.
Snowflake
To add our development environment we'll want to get our account identifier. Once copied we'll make sure we replace the .
with a -
otherwise it won't find the account.
We'll select snowflake and give the connection a name. For the connection settings you'll want to add your account identifier as the account. Please remember to swap .
with a -
otherwise it won't find the account. For the database we'll use DBT
, warehouse = development
and role = SYSADMIN
.
Once saved, dbt will not redirect you to the setup so please click Credentials
and then the project. This will prompt you to click a link that will take you back to the setup page.
If your user is using MFA
If your planned development user is using MFA. This connection test will ask for MFA authentication.
Now we'll want to enter our own development credentials and then select test connection
to validate everything.
Once tested you will see a complete
status. From there we'll click save.
Git
Next we'll want to add our git reposity. If you have not created one yet, this would be a great time before we connect to it. I named mine dbt
.
Once you authenticate with your git provider, a list of git repos will show. Select the one you want to use.
Run first models
Great our development environment connection is setup. Lets build our first models and see them in Snowflake.
Lets initialize the project code.
We can see a sample project has been added to our branch.
Before we build these models lets remove some code so that everything builds successfully. DBT has setup up this code for learning but we are more intrested in getting everything working.
If your user is using MFA - Please enable token caching before uploading
If your development user is using MFA. Please enable token caching or else it will ask you for authentication everytime you run each dbt model. In this case will we ask at least 6-7 times.
Now lets build our code by going to the bottom of the page and entering dbt build
and hitting enter. This will build all our models.
We can see now that all our current branches models have built successfully.
We can view those built models in our Snowflake account.
Finally we will commit those changes to our branch.
Production
Great now that we have our development environment setup we can start adding new users and all they will have to do is add thier development credientials. Lets setup our product environment that will curate our models on a regular bases based on our main
branch.
Environment
Lets start by committing our changes to the branch.
Once commit DBT will give us the option to create a pull request. Lets commit our branch to main branch.
Give the PR a description and click "create pull request".
After it's created lets merge the code changes.
After it's merged lets delete the branch to keep our git clean.
Next lets go back to DBT to setup the environment.
Lets create a new environment.
Lets give our environment a name, select deplyment type of production
and connection of Snowflake we created earlier.
Lets add our connection variables. The image shows what everything should be if you used our setup code. The password comes from that setup code. If your want to use key-pair instead of username/password, check our key-pair tutorial.
Once finished head back to the top and click save.
Job
Jobs run dbt code in our environment on a regular bases. Lets use the left navbar to go to deploy and then jobs.
We'll give our job a name. The environment should be production and we want to run the command dbt build
similar to when we were in development. Next we'll select to generate docs and run on a schedule. Click save when finished.
Now that we created the job, lets run it.
We can see the job is now running, lets click in and see what it's doing.
You can see the steps dbt will take to run this job. It may take 20 seconds for it to finish.
Result
Once the job is completed we can go to Snowflake to see our production jobs result in our production schema.
Now we can go back to the dashboard to see all the metadata of our job and run history.
Documentation
Now that our production job has run lets see our documentation. This has a little setup to know which job the docs should look at when displaying results.
Lets start by going to account settings in the bottom left of the page.
We'll go to project, select the project and finally edit the project.
We'll want to update the description, and the job we want to associate the documentation to. Finally click save.