check_source_existence

/*
This macro is to check the existence of a source

To check whether a source table exist, see below
https://discourse.getdbt.com/t/writing-packages-when-a-source-table-may-or-may-not-exist/1487

*/

{% macro check_source_existence(schema_table_IN, object_table_IN) %}

{%- set source_relation = adapter.get_relation(
      database=source(schema_table_IN, object_table_IN).database,
      schema=source(schema_table_IN, object_table_IN).schema,
      identifier=source(schema_table_IN, object_table_IN).name) -%}
{% set table_exists = source_relation is not none %}

{{ return(table_exists) }}

{% endmacro %}