{% macro insert_A_WORKFLOW_HISTORY() %}

{% if execute %}

    {% set insert_A_WORKFLOW_HISTORY %}
        INSERT INTO {{ source('control_tables', 'A_WORKFLOW_HISTORY') }} (SERVICE_NAME, A_WORKFLOW_HISTORY_KEY, ORCHESTRATION_RUN_ID, WORKFLOW_NAME, WORKFLOW_START, WORKFLOW_SUCCESSFUL, DBT_INVOCATION_ID)
        VALUES ('{{ var("input_service_name") }}', {{ source('control_sequences','A_WORKFLOW_HISTORY_SEQ') }}.NEXTVAL, '{{ var("orchestration_run_id") }}', '{{ var("workflow_name") }}', cast(current_timestamp as timestamp(0)), 'R', '{{ invocation_id }}')
    {% endset %}

    {% do run_query(insert_A_WORKFLOW_HISTORY) %}

{% endif %}
{% endmacro %}