> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datafold.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Slim Diff

> Choose which downstream tables to diff to optimize time, cost, and performance.

By default, Datafold diffs all modified models and downstream models. However, it won't make sense for all organizations to diff every downstream table every time you make a code update. Tradeoffs of time, cost, and risk must be considered.

That's why we created Slim Diff.

With Slim Diff enabled, Datafold will only diff models with dbt code changes in your Pull Request (PR).

<Frame>
  <img src="https://mintcdn.com/datafold/6zQ11m2yiOVjYXTT/images/deployment_testing/slim-diff-diagram.png?fit=max&auto=format&n=6zQ11m2yiOVjYXTT&q=85&s=7f8df7c3088ee7de6303eba741627e5b" width="1600" height="1073" data-path="images/deployment_testing/slim-diff-diagram.png" />
</Frame>

## Setting up Slim Diff

In Datafold, Slim Diff can be enabled by adjusting your diff settings by navigating to Settings → Integrations → CI → Select your CI tool → Advanced Settings and check the Slim Diff box:

<Frame>
  <img src="https://mintcdn.com/datafold/6zQ11m2yiOVjYXTT/images/deployment_testing/slim-diff.png?fit=max&auto=format&n=6zQ11m2yiOVjYXTT&q=85&s=47702904f2d17c9cdeb39b99e6454b95" width="883" height="688" data-path="images/deployment_testing/slim-diff.png" />
</Frame>

## Diffing only modified models

With this setting turned on, only the modified models will be diffed by default.

<Frame>
  <img src="https://mintcdn.com/datafold/7pWtpSckJi2T0xZR/images/208832523-c3552417-8975-4460-91ed-fd7b0df7d7b7.png?fit=max&auto=format&n=7pWtpSckJi2T0xZR&q=85&s=e0707c61bf5e85634a3924ef30650492" width="1886" height="802" data-path="images/208832523-c3552417-8975-4460-91ed-fd7b0df7d7b7.png" />
</Frame>

## Diff individual downstream models

Once Datafold has diffed only the modified models, you still have the option of diffing individual downstream models right within your PR.

<Frame>
  <img src="https://mintcdn.com/datafold/7pWtpSckJi2T0xZR/images/208832659-e3cdb9d9-c468-459f-85ff-990b2a68b57c.png?fit=max&auto=format&n=7pWtpSckJi2T0xZR&q=85&s=dc39127b63705424aa89cc2f504d7b4a" width="1734" height="700" data-path="images/208832659-e3cdb9d9-c468-459f-85ff-990b2a68b57c.png" />
</Frame>

## Diff all downstream models

You can also add the `datafold:diff-all-downstream` label within your PR, which will automatically diff *all* downstream models.

<Frame>
  <img src="https://mintcdn.com/datafold/7pWtpSckJi2T0xZR/images/208833093-f853bde7-d12a-4b9f-b5ac-a4d8d9666076.png?fit=max&auto=format&n=7pWtpSckJi2T0xZR&q=85&s=ee1105716276b26d932c303a0db51733" width="1884" height="870" data-path="images/208833093-f853bde7-d12a-4b9f-b5ac-a4d8d9666076.png" />
</Frame>

## Explicitly define which models to always diff

Finally, with Slim Diff turned on, there might be certain models or subdirectories that you want to *always* diff when downstream. You can think of this as an exclusion to the Slim Diff behavior.

Apply the `slim_diff: diff_when_downstream` meta tag to individual models or entire folders in your `dbt_project.yml` file:

```Bash theme={null}
models:
  <project_name>:
    <directory_name>:
      +materialized: view
      <model_name>:
        +meta:
          datafold:
            datadiff:
              slim_diff: diff_when_downstream

    <directory_name>:
      +meta:
        datafold:
          datadiff:
            slim_diff: diff_when_downstream
```

These meta tags can also be added in individual yaml files or in config blocks. More details about using meta tags are available in [the dbt docs](https://docs.getdbt.com/reference/resource-configs/meta).

With this configuration in place, Slim Diff will prevent downstream models from being run *unless* they have been designated as exceptions with the `slim_diff: diff_when_downstream` dbt meta tag.

<Frame>
  <img src="https://mintcdn.com/datafold/7pWtpSckJi2T0xZR/images/208833985-031a04fe-864a-4487-8a64-ec80e4c232e1.png?fit=max&auto=format&n=7pWtpSckJi2T0xZR&q=85&s=1f117e6880687fabc1575f4964a91722" width="1924" height="874" data-path="images/208833985-031a04fe-864a-4487-8a64-ec80e4c232e1.png" />
</Frame>

As usual, once the PR has been opened, you'll still have the option of diffing individual downstream models that weren't diffed, or diffing all downstream models using the `datafold:diff-all-downstream` label.
