latest_model_refresh

/*
Used to get the latest refresh date of the current model. This looks up the date from the DBT_MODEL_LAST_RUN table in EDW_CONFIG in snowflake using {{this}} to determine the model
Returns a date and if the date is null then it will return 01/01/2000
*/

{% macro latest_refresh_date() %}
    case when  ( SELECT LAST_BATCH_START_TIME FROM {{ target.database }}.EDW_CONFIG.DBT_MODEL_LAST_RUN where job_name ='{{ this }}' ) is null
     then  to_date('01/01/2000 00:00:00', 'dd/mm/yyyy hh24:mi:ss')
     else  ( SELECT LAST_BATCH_START_TIME FROM {{ target.database }}.EDW_CONFIG.DBT_MODEL_LAST_RUN where job_name ='{{ this }}' )
     end
{% endmacro %}