Understanding Model Access, Contracts & Styling in dbt Core

May 22, 2024

What is Model Access in dbt-core?

In dbt-core, model access is a term that refers to the ability of users to designate certain models as either "private" or "public". Private models are exclusively accessible within a specific group, while public models can be referenced by other teams. This feature allows for better control and governance over data models within a dbt project.

# Example of designating a model as private
models: my_project_name: marts: customers: +group: customer_success

The above code snippet demonstrates how to apply a group label to a subdirectory in a dbt project, effectively making the model private. In this case, the 'customers' model is designated as part of the 'customer_success' group.

  • Private Model: A model that can only be used within a specific group.
  • Public Model: A model that can be referenced by other teams.
  • Group Label: A label used to designate a model as part of a specific group.

How to Apply Group Labels in dbt?

Applying a group label to a subdirectory in a dbt project is done in the dbt_project.yml file. The syntax is 'models: project_name: directory: subdirectory: +group: group_name'. This allows you to specify which group a model belongs to.

# Example of applying a group label
finance: +group: finance

In the code example, the 'finance' model is assigned to the 'finance' group. This means that only members of the 'finance' group can access this model.

  • Group Label Application: The process of assigning a model to a specific group.
  • dbt_project.yml: The file where group labels are applied.
  • Model Group: The group to which a model is assigned.

What are Model Contracts in dbt?

Model contracts in dbt are used to define column names, data types, and constraints. This helps to avoid breaking changes for downstream queries. It's a form of model governance that ensures the integrity and reliability of your data models.

It's important to understand that they are a critical part of maintaining and managing your dbt models. They help ensure that changes to your models don't negatively impact downstream queries.

  • Model Contracts: Definitions of column names, data types, and constraints in a model.
  • Downstream Queries: Queries that are dependent on the data from a model.
  • Model Governance: The process of managing and maintaining data models.

How to Manage Model Versions in dbt?

Managing model versions in dbt involves creating a new model version to provide a smoother upgrade path when a breaking change is unavoidable. This allows for better control over the evolution of your data models and minimizes disruption to dependent queries.

It's a crucial aspect of dbt model governance. It ensures that changes to your models are handled in a way that minimizes impact on dependent queries.

  • Model Versions: Different iterations of a model.
  • Breaking Change: A change that disrupts dependent queries.
  • Upgrade Path: The process of transitioning from one model version to another.

What is Model Styling in dbt?

Model styling in dbt involves using underscores for naming models and pluralizing models. This is a convention that helps maintain consistency and readability in your dbt projects.

It's a convention that's widely followed in dbt projects. It helps ensure that your models are named in a consistent and readable manner.

  • Model Styling: The convention of using underscores for naming models and pluralizing models.
  • Underscores: Used in model names for readability and consistency.
  • Pluralizing Models: The practice of using plural names for models.

Keep reading

See all