Now that we've successfully run our sample query in BigQuery, and chosen the way we want to develop, we can create a dbt project! In this step, we'll create a starter project with example models, before we build our own models.
Create a repository
- Create a new GitHub repository here named
- Click Create repository (without
.gitignoreand without a license).
Create a project
The dbt CLI comes with a command to help you scaffold a dbt project. To create your dbt project:
1. Ensure dbt is installed by running
$ dbt --version
- Run the
$ dbt init jaffle-shop
cdinto your project:
$ cd jaffle-shop
You can use
pwd to confirm that you are in the right spot.
- Open your project (i.e. the directory you just created) in a code editor like Atom or VSCode. You should see a directory structure with
.ymlfiles that were generated by the
- Update the following values in the
name: jaffle_shop # this normally says my_new_package...profile: jaffle_shop # this normally says default...models:jaffle_shop: #this normally says my_new_package. It should match the value for `name:`...
Connect to BigQuery
When developing locally, dbt connects to your data warehouse using a profile — a yaml file with all the connection details to your warehouse.
- Create a file in the
- Move your BigQuery keyfile into this directory.
- Copy the following into the file — make sure you update the values where indicated.
jaffle_shop: # this needs to match the profile: in your dbt_project.yml filetarget: devoutputs:dev:type: bigquerymethod: service-accountkeyfile: /Users/claire/.dbt/dbt-user-creds.json # replace this with the full path to your keyfileproject: grand-highway-265418 # Replace this with your project iddataset: dbt_alice # Replace this with dbt_your_name, e.g. dbt_bobthreads: 1timeout_seconds: 300location: USpriority: interactive
- Execute the debug command from your project to confirm that you can successfully connect
$ dbt debug
Confirm that the last line of the output is
Connection test: OK connection ok.
Perform your first dbt run
Our sample project has some example models in it. We're going to check that we can run them to confirm everything is in order.
- Execute the
runcommand to build the example models:
$ dbt run
You should have an ouput that looks like this:
Commit your changes
We need to commit our changes so that our repository has up-to-date code.
- Link the GitHub repository you created to your dbt project by running the following commands. Make sure you use the correct git URL for your repository.
$ git init$ git commit -m "Create a dbt project"$ git remote add origin https://github.com/USERNAME/dbt-tutorial.git$ git push -u origin master