# Run dbt test on a single model.yml related to the table alias with different schema

**URL:** <https://discourse.getdbt.com/t/run-dbt-test-on-a-single-model-yml-related-to-the-table-alias-with-different-schema/9182>\
**Category:** Help\
**Tags:** jinja, testing\
**Created:** [July 18, 2023, 9:16am UTC](https://discourse.getdbt.com/t/run-dbt-test-on-a-single-model-yml-related-to-the-table-alias-with-different-schema/9182 "2023-07-18T09:16:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoine.falieres](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/antoine.falieres/32/2737_2.png) [@antoine.falieres](https://discourse.getdbt.com/u/antoine.falieres)\
**Post date:** [July 18, 2023, 9:16am UTC](https://discourse.getdbt.com/t/run-dbt-test-on-a-single-model-yml-related-to-the-table-alias-with-different-schema/9182/1 "2023-07-18T09:16:54Z")

</div>

Hello !  
I’ve got 2 tables : `my_table_1` and `my_table_2` created from a model `my_table` with a dynamic alias where the alias is set up through the dag. The differences with the two of them are the alias of course but also a column name.  
In other words, the `my_table_1` schema has the common columns whereas the `my_table_2` schema has a column `country` populated along with the common columns shared with `my_table_1`.  
Creating the tables with the different schema is straight forward but I’m stuck with the `my_table.yml` and its schema for the testing.  
What I’m trying to achieve is to run the `my_table.yml` using `dbt test` that would read the `my_table_1` schema **without** the column `country` but would do it with the `my_table_2` schema **with** the column `country`  
I tried to add a if-statement in the yml file but it doesn’t seem to work (see below).

Do you have any idea how I can achieve that please ?

```auto
my_table.yml 

models:
    - marts:
      name: my_table      
      columns:
{% if alias == "my_table_2" %}
       - name: country
         tests:
           - not_null:
               config:
                 severity: error
{% endif %}
        - name: id
          tests:
           - not_null:
               config:
                 severity: error
        - name: name
          tests:
           - not_null:
               config:
                 severity: error

```

---

<div class="post-metadata">

**Author:** ![antoine.falieres](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/antoine.falieres/32/2737_2.png) [@antoine.falieres](https://discourse.getdbt.com/u/antoine.falieres)\
**Post date:** [July 19, 2023, 9:02pm UTC](https://discourse.getdbt.com/t/run-dbt-test-on-a-single-model-yml-related-to-the-table-alias-with-different-schema/9182/2 "2023-07-19T21:02:13Z")

</div>

```auto
my_table.yml 

models:
    - marts:
      name: my_table
      tests:
        - dbt_utils.expression_is_true:
            expression: "{% if config.get('alias') == 'my_table_2' %} COUNTRY IS NOT NULL {% else %} TRUE {% endif %}"

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [July 26, 2023, 9:03pm UTC](https://discourse.getdbt.com/t/run-dbt-test-on-a-single-model-yml-related-to-the-table-alias-with-different-schema/9182/3 "2023-07-26T21:03:14Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
