Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add command examples to run model versions #4501

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions website/docs/docs/collaborate/govern/model-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,32 @@ dbt.exceptions.AmbiguousAliasError: Compilation Error
We opted to use `generate_alias_name` for this functionality so that the logic remains accessible to end users, and could be reimplemented with custom logic.
:::

### Run a model with multiple versions

To run a model with multiple versions, you can use the [`--select` flag](/reference/node-selection/syntax). For example:

- Run all versions of `dim_customers`:

```bash
dbt run --select dim_customers # Run all versions of the model
```
- Run only version 2 of `dim_customers`:

You can use either of the following commands (both achieve the same result):

```bash
dbt run --select dim_customers.v2 # Run a specific version of the model
dbt run --select dim_customers_v2 # Alternative syntax for the specific version
```

- Run the latest version of `dim_customers` using the `--select` flag shorthand:

```bash
dbt run -s dim_customers version:latest # Run the latest version of the model
```

These commands provide flexibility in managing and executing different versions of a dbt model.

### Optimizing model versions

How you define each model version is completely up to you. While it's easy to start by copy-pasting from one model's SQL definition into another, you should think about _what actually is changing_ from one version to another.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The latest version of this model. The "latest" version is relevant for:

This value can be a string or a numeric (integer or float) value. It must be one of the [version identifiers](/reference/resource-properties/versions#v) specified in this model's list of `versions`.

To run the latest version of a model, you can use the [`--select` flag](/reference/node-selection/syntax). Refer to [Model versions](/docs/collaborate/govern/model-versions#run-a-model-with-multiple-versions) for more information and syntax.

## Default

If not specified for a versioned model, `latest_version` defaults to the largest [version identifier](/reference/resource-properties/versions#v): numerically greatest (if all version identifiers are numeric), otherwise the alphabetically last (if they are strings).
Expand Down
3 changes: 3 additions & 0 deletions website/docs/reference/resource-properties/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ The value of the version identifier is used to order versions of a model relativ

In general, we recommend that you use a simple "major versioning" scheme for your models: `1`, `2`, `3`, and so on, where each version reflects a breaking change from previous versions. You are able to use other versioning schemes. dbt will sort your version identifiers alphabetically if the values are not all numeric. You should **not** include the letter `v` in the version identifier, as dbt will do that for you.

To run a model with multiple versions, you can use the [`--select` flag](/reference/node-selection/syntax). Refer to [Model versions](/docs/collaborate/govern/model-versions#run-a-model-with-multiple-version) for more information and syntax.


### `defined_in`

The name of the model file (excluding the file extension, e.g. `.sql` or `.py`) where the model version is defined.
Expand Down
Loading