version: 2
models:
  - name: descendant_model
    columns:
      - name: favorite_color
        tests:
          - relationships:
             to: source('test_source', 'test_table')
             field: favorite_color

sources:
  - name: test_source
    loader: custom
    freshness:
      warn_after: {count: 10, period: hour}
      error_after: {count: 1, period: day}
    schema: "{{ var(env_var('DBT_TEST_SCHEMA_NAME_VARIABLE')) }}"
    quoting:
      identifier: True
    tags:
      - my_test_source_tag
    tables:
      - name: test_table
        identifier: source
        loaded_at_field: "{{ var('test_loaded_at') | as_text }}"
        freshness:
          error_after: {count: 18, period: hour}
        tags:
          - my_test_source_table_tag
        columns:
          - name: favorite_color
            description: The favorite color
          - name: id
            description: The user ID
            tests:
              - unique
              - not_null
            tags:
              - id_column
          - name: first_name
            description: The first name of the user
            tests: []
          - name: email
            description: The email address of the user
          - name: ip_address
            description: The last IP address the user logged in from
          - name: updated_at
            description: The last update time for this user
        tests:
          - relationships:
              # do this as a table-level test, just to test out that aspect
              column_name: favorite_color
              to: ref('descendant_model')
              field: favorite_color
      - name: other_test_table
        identifier: other_table
        columns:
          - name: id
            tests:
              - not_null
              - unique
            tags:
              - id_column
      - name: disabled_test_table
        freshness: null
        loaded_at_field: "{{ var('test_loaded_at') | as_text }}"
  - name: other_source
    schema: "{{ var('test_run_schema') }}"
    quoting:
      identifier: True
    tables:
      - name: test_table
        identifier: other_source_table
  - name: external_source
    schema: "{{ var('test_run_alt_schema', var('test_run_schema')) }}"
    tables:
      - name: table
