# Snapshots rebuilt in every run

**URL:** <https://discourse.getdbt.com/t/snapshots-rebuilt-in-every-run/11975>\
**Category:** Help\
**Tags:** snapshots\
**Created:** [February 9, 2024, 10:54am UTC](https://discourse.getdbt.com/t/snapshots-rebuilt-in-every-run/11975 "2024-02-09T10:54:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fije\_red](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fije\_red](https://discourse.getdbt.com/u/fije_red)\
**Post date:** [February 9, 2024, 10:54am UTC](https://discourse.getdbt.com/t/snapshots-rebuilt-in-every-run/11975/1 "2024-02-09T10:54:22Z")

</div>

## The problem I’m having

Every time I run dbt build or dbt snapshot, the snapshots are rebuilt. It isn’t checking the previous data, only inserting the most recent data with new dates.

## The context of why I’m trying to do this

The source for the snapshot is a table built in the same model to check inconsistencies on the data, my goal is to check when those inconsistencies change.  
Table:

| id | dimension | issue |
| --- | --- | --- |
| 1 | uniqueness | duplicated product |
| 3 | uniqueness | duplicated product |
| 2 | accuracy | wrong category |

I am expecting that when some of the issue gets solved, the dbt\_valid\_to column of the snapshot table be populated. But currently the snapshot is being rebuilt even without any change in the source table.

## What I’ve already tried

I already tried only one or two columns in check\_cols, without the invalidate\_hard\_deletes.  
I already changed the query.  
I already tried to manually change one row and run snapshot, but all the table is rebuilt.  
I already tried the timestamp strategy.

## Some example code or error messages

```auto
    {{
        config(
            target_schema=generate_schema_name("DQ"),
            unique_key='id',
            strategy="check",
            invalidate_hard_deletes=True,
            check_cols="all",
        )
    }}

```

The compiled code doesn’t have any merge/insert statement, only create

---

<div class="post-metadata">

**Author:** ![nitin](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@nitin](https://discourse.getdbt.com/u/nitin)\
**Post date:** [February 12, 2024, 9:14am UTC](https://discourse.getdbt.com/t/snapshots-rebuilt-in-every-run/11975/2 "2024-02-12T09:14:42Z")

</div>

Hi @fije_red ,  
I am facing same issue, were you able to find solution for this.

Regards  
Nitin

---

<div class="post-metadata">

**Author:** ![fije\_red](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fije\_red](https://discourse.getdbt.com/u/fije_red)\
**Post date:** [February 12, 2024, 9:31am UTC](https://discourse.getdbt.com/t/snapshots-rebuilt-in-every-run/11975/3 "2024-02-12T09:31:26Z")

</div>

I found the solution after checking the slack community.  
The issue was in the macros generate\_schema\_name, I tested with the final name of the schema instead of the macro and it worked.  
Then I realized that were missing some “-” in my macros, so…  
fom this:

```auto
        {% endif -%}

    {% endif -%}

{% endmacro -%}

```

I ended up with this and it’s working well:

```auto
        {%- endif -%}

    {%- endif -%}

{%- endmacro -%}

```
