Civis Studio is a great place to develop your dbt projects before productionalizing them as dbt scripts and running them in workflows. Below, we outline how to configure a studio for a successful dbt development experience.
Configure Settings
Before deploying the studio, select the database(s) you’d like to reference in your dbt models, and connect to a git repository.
(Optional) Connect to git
A git connection is recommended to allow you to easily access your code from other parts of Platform, but it is not required to get started!
Define Parameters: Select target database(s)
To create your dbt models, you’ll need to select your target database and credential. You can easily inject all you’ll need into the studio environment by defining “database” type parameters in the studio’s settings, and selecting the desired database and credential from the dropdowns:
You can then reference the generated environment variables in your dbt profile. See “Configure your profiles.yml” below.
Start your studio and develop dbt projects
Now that you have your parameters set up, you can begin developing your dbt projects. See the dbt Core guide for more information. You can skip the installation step, as Civis studio comes with the latest dbt Core and adapters already installed.
Configure your profiles.yml
Once you’ve selected your target database, you will need to create or update a profiles.yml file with the relevant connection information.
For an example profile, see the civis-studio profile in platform-code-examples profiles.yml.
Note: Since studios support defining multiple database parameters at once, their environment variable naming scheme is slightly different from that of Platform’s dbt scripts.
For example, these would be the generated environment variables for a database parameter named “my_database”:
| dbt Script | Civis Studio |
| DBT_ENV_SECRET_DATABASE_PASSWORD | DBT_ENV_SECRET_MY_DATABASE_CREDENTIAL_PASSWORD |
| DATABASE_NAME | MY_DATABASE_DATABASE |
| DATABASE_TYPE | MY_DATABASE_TYPE |
| // redshift/postgres specific | // redshift/postgres specific |
| DATABASE_PORT | MY_DATABASE_PORT |
| DATABASE_HOST | MY_DATABASE_HOST |
| DATABASE_USERNAME | MY_DATABASE_CREDENTIAL_USERNAME |
| // bigquery specific | // bigquery specific |
| GCP_PROJECT_ID | MY_DATABASE_GCP_PROJECT_ID |
| GCP_AUTH_METHOD | MY_DATABASE_GCP_AUTH_METHOD |
| DBT_ENV_SECRET_GCP_ACCESS_TOKEN | DBT_ENV_SECRET_MY_DATABASE_GCP_ACCESS_TOKEN |
(optional) Install dbt Power User extension
We enjoy using the dbt Power User extension to help with dbt development in studios. This extension provides a number of helpful features for developing dbt in a VS Code environment, including coding assistance and preview tools.
Install the extension from the Extensions pane (building block icon) on the left side of the studio, and follow the welcome instructions from there.
Publish your dbt script
In this section, we’ll walk through getting your new or updated dbt project from your studio to a dbt script. This assumes the studio work was done with a git connection. If not, go back and add a git connection before proceeding.
Commit and push changes to git
Once you’re happy with your dbt project, you’re ready to move it to production. First, you’ll need to commit and push your changes from the studio. This is possible via the command line, as well as via the GitHub extension on the lefthand side of the deployed studio. Below, we demonstrate committing via the terminal command line to a branch entitled “update-dbt-project”:
and pushing to the remote repository via the extension:
Configure the dbt script
With your changes in the remote repository, existing and new dbt scripts will be able to use the updated project. To configure a new dbt script, make sure to
- Select the same repository and branch that were used in the studio
- Select the same database parameter (unless you want your production project to use different database)
- Check “Auto Generate profiles.yml”. Alternatively, you may manually update profiles.yml to use the dbt script syntax for environment variables.
(optional) Automate
Utilize Platform’s automation features to run your dbt script on a schedule, or regularly after other tasks finish as part of a workflow!
Comments
0 comments
Please sign in to leave a comment.