Custom strategy - macro

Hi.
I’m trying to understand how to create custom snapshot strategy.
I’d like to change the behaviour of snapshot. Column dbt_valid_to would be 9999-12-31 date and not a null date.

To do this, I created a new strategy : “mystrategy”.

I overwrite some macros like snapshot_staging_table, or build_snapshot_table to change the way code is generated.

But I want this behaviour is only for “mystrategy”. By overwriting the macros, I changed the behaviour for all strategies. So, the “check” strategy has changed too.

How can I only change the behaviour for the “mystrategy” strategy, and not all strategies ?

Thanks for your help :slight_smile:
Regards.

Have you seen the docs on creating a custom strategy? strategy | dbt Developer Hub

You should only need to make one new macro, not overwrite any existing macros

I created a new strategy like said in the docs.
But my strategy uses other macros behind the scenes.

When executing, my strategy uses default macros to generate rows in my tables. For example, it uses defaut build_snapshot_table :

{% macro default__build_snapshot_table(strategy, sql) %}

    select *,
        {{ strategy.scd_id }} as dbt_scd_id,
        {{ strategy.updated_at }} as dbt_updated_at,
        {{ strategy.updated_at }} as dbt_valid_from,
        nullif({{ strategy.updated_at }}, {{ strategy.updated_at }}) as dbt_valid_to
    from (
        {{ sql }}
    ) sbq
{% endmacro %}

But I want this behaviour in my custom strategy :


{% macro build_snapshot_table(strategy, sql) %}

    select *,
        {{ strategy.scd_id }} as dbt_scd_id,
        {{ strategy.updated_at }} as dbt_updated_at,
        {{ strategy.updated_at }} as dbt_valid_from,
        to_TIMESTAMP('9999-12-31 23:59:59.999') as dbt_valid_to
    from (
        {{ sql }}
    ) sbq

{% endmacro %}

How to do this only for my strategy, and not all strategies ?

Can you post the code of your strategy? I expect that you’ll just have to give your macro a different name, and call that macro in your custom materialization.