Columns

Full Example
contracts:
  models:
  - columns:
    - filter:
      - tag:
          tags:
          - tag1
          - tag2
      - meta:
          meta:
            key1: val1
            key2:
            - val2
            - val3
      validations:
      - has_allowed_meta_keys:
          keys:
          - key1
          - key2
      - has_matching_description:
          ignore_whitespace: false
          case_insensitive: true
          compare_start_only: false
      - has_matching_data_type:
          ignore_whitespace: true
          case_insensitive: true
          compare_start_only: true
      - has_matching_index:
          ignore_whitespace: false
          case_insensitive: true
          compare_start_only: true
      - has_allowed_meta_values:
          meta:
            key1: val1
            key2:
            - val2
            - val3
      generator:
        exclude:
        - data_type
        - description
        description:
          overwrite: false
          terminator: __END__
        data_type:
          overwrite: false

Filters

Filters (or Conditions) for reducing the scope of the contract. You may limit the number of columns processed by the rules of this contract by defining one or more of the following filters.

name

Filter columns based on their names.

Schema
name:
  include:
    default: []
    description: Patterns to match against for values to include
    items:
      type: string
    type: array
  exclude:
    default: []
    description: Patterns to match against for values to exclude
    items:
      type: string
    type: array
  match_all:
    default: false
    description: When True, all given patterns must match to be considered a match
      for either pattern type
    type: boolean
Example
name:
  include: .*i\s+am\s+a\s+regex\s+pattern.*
  exclude: .*i\s+am\s+a\s+regex\s+pattern.*
  match_all: false

You may also define the parameters for include directly on the definition like below.

name: .*i\s+am\s+a\s+regex\s+pattern.*

tag

Filter columns based on their tags.

Schema
tag:
  tags:
    default: []
    description: The tags to match on
    items:
      type: string
    type: array
Example
tag:
  tags: tag1

You may also define the parameters for tags directly on the definition like below.

tag:
- tag1
- tag2

meta

Filter columns based on their meta values.

Schema
meta:
  meta:
    additionalProperties:
      items:
        type: string
      type: array
    description: The mapping of meta keys to their allowed values
    type: object
Example
meta:
  meta:
    key1: val1
    key2:
    - val2
    - val3

Validations

Validations (or Terms) to apply to the resources of this contract. These enforce certain standards that must be followed in order for the contract to be fulfilled.

has_description

Check whether the columns have descriptions defined in their properties.

Note

This term does not need further configuration. Simply define the term’s name as an item in your configuration.

has_required_tags

Check whether the columns have the expected set of required tags set.

Schema
has_required_tags:
  tags:
    default: []
    description: The required tags
    items:
      type: string
    type: array
Example
has_required_tags:
  tags: tag1

You may also define the parameters for tags directly on the definition like below.

has_required_tags:
- tag1
- tag2

has_allowed_tags

Check whether the columns have only tags set from a configured permitted list.

Schema
has_allowed_tags:
  tags:
    default: []
    description: The allowed tags
    items:
      type: string
    type: array
Example
has_allowed_tags:
  tags:
  - tag1
  - tag2

You may also define the parameters for tags directly on the definition like below.

has_allowed_tags: tag1

has_required_meta_keys

Check whether the columns have the expected set of required meta keys set.

Schema
has_required_meta_keys:
  keys:
    default: []
    description: The required meta keys
    items:
      type: string
    type: array
Example
has_required_meta_keys:
  keys:
  - key1
  - key2

You may also define the parameters for keys directly on the definition like below.

has_required_meta_keys:
- key1
- key2

has_allowed_meta_keys

Check whether the columns have only meta keys set from a configured permitted list.

Schema
has_allowed_meta_keys:
  keys:
    default: []
    description: The allowed meta keys
    items:
      type: string
    type: array
Example
has_allowed_meta_keys:
  keys: key1

You may also define the parameters for keys directly on the definition like below.

has_allowed_meta_keys:
- key1
- key2

has_allowed_meta_values

Check whether the columns have only meta values set from a configured permitted mapping of keys to values.

Schema
has_allowed_meta_values:
  meta:
    additionalProperties:
      items:
        type: string
      type: array
    description: The mapping of meta keys to their allowed values
    type: object
Example
has_allowed_meta_values:
  meta:
    key1: val1
    key2:
    - val2
    - val3

exists

Check whether the columns exist in the database.

Note

This term does not need further configuration. Simply define the term’s name as an item in your configuration.

has_tests

Check whether columns have an appropriate number of tests configured.

Schema
has_tests:
  min_count:
    default: 1
    description: The minimum count allowed.
    minimum: 1
    type: integer
  max_count:
    anyOf:
    - exclusiveMinimum: 0
      type: integer
    - type: 'null'
    default: null
    description: The maximum count allowed.
Example
has_tests:
  min_count: 3
  max_count: 5

You may also define the parameters for min_count directly on the definition like below.

has_tests: 2

has_expected_name

Check whether columns have an expected name based on their data type. Matches the column names against a set of patterns mapped to specific data types.

Schema
has_expected_name:
  ignore_whitespace:
    default: false
    description: Ignore any whitespaces when comparing data type keys.
    type: boolean
  case_insensitive:
    default: false
    description: Ignore cases and compare data type keys only case-insensitively.
    type: boolean
  compare_start_only:
    default: false
    description: Match data type keys when the two values start with the same value.
      Ignore the rest of the data type definition in this case.
    type: boolean
  patterns:
    additionalProperties:
      items:
        type: string
      type: array
    description: A map of data types to regex patterns for which to validate names
      of columns which have the matching data type.To define a generic contract which
      can apply to all unmatched data types, specify the data type key as `null`.
    type: object
Example
has_expected_name:
  ignore_whitespace: false
  case_insensitive: false
  compare_start_only: false
  patterns:
    BOOLEAN:
    - (is|has|do)_.*
    TIMESTAMP:
    - .*_at
    null:
    - name_.*

You may also define the parameters for ignore_whitespace directly on the definition like below.

has_expected_name: false

has_data_type

Check whether columns have a data type configured in their properties.

Note

This term does not need further configuration. Simply define the term’s name as an item in your configuration.

has_matching_description

Check whether the descriptions configured in columns’ properties matches the descriptions in the database.

Schema
has_matching_description:
  ignore_whitespace:
    default: false
    description: Ignore any whitespaces when comparing data type keys.
    type: boolean
  case_insensitive:
    default: false
    description: Ignore cases and compare data type keys only case-insensitively.
    type: boolean
  compare_start_only:
    default: false
    description: Match data type keys when the two values start with the same value.
      Ignore the rest of the data type definition in this case.
    type: boolean
Example
has_matching_description:
  ignore_whitespace: true
  case_insensitive: true
  compare_start_only: false

You may also define the parameters for ignore_whitespace directly on the definition like below.

has_matching_description: false

has_matching_data_type

Check whether the data type configured in a column’s properties matches the data type in the database.

Schema
has_matching_data_type:
  ignore_whitespace:
    default: false
    description: Ignore any whitespaces when comparing data type keys.
    type: boolean
  case_insensitive:
    default: false
    description: Ignore cases and compare data type keys only case-insensitively.
    type: boolean
  compare_start_only:
    default: false
    description: Match data type keys when the two values start with the same value.
      Ignore the rest of the data type definition in this case.
    type: boolean
Example
has_matching_data_type:
  ignore_whitespace: true
  case_insensitive: false
  compare_start_only: true

You may also define the parameters for ignore_whitespace directly on the definition like below.

has_matching_data_type: false

has_matching_index

Check whether the index position within the properties of a column’s table matches the index position in the database.

Schema
has_matching_index:
  ignore_whitespace:
    default: false
    description: Ignore any whitespaces when comparing data type keys.
    type: boolean
  case_insensitive:
    default: false
    description: Ignore cases and compare data type keys only case-insensitively.
    type: boolean
  compare_start_only:
    default: false
    description: Match data type keys when the two values start with the same value.
      Ignore the rest of the data type definition in this case.
    type: boolean
Example
has_matching_index:
  ignore_whitespace: true
  case_insensitive: false
  compare_start_only: false

You may also define the parameters for ignore_whitespace directly on the definition like below.

has_matching_index: false

Generator

You may also configure a Generator for your contract. A Generator creates/updates properties files for columns from the attributes found on the database resource.

Schema
generator:
  exclude:
    default: []
    description: The fields to exclude from the generated properties.
    items:
      enum:
      - description
      - data_type
      type: string
    type: array
  description:
    $ref: '#/$defs/SetColumnDescription'
    default:
      overwrite: true
      terminator: null
    description: Configuration for setting the column description
  data_type:
    $ref: '#/$defs/SetDataType'
    default:
      overwrite: true
    description: Configuration for setting the column data type

defs

SetColumnDescription:
  overwrite:
    default: true
    description: Whether to overwrite existing properties with properties from the
      database. When false, keeps the values already present in the properties if
      present.
    type: boolean
  terminator:
    anyOf:
    - type: string
    - type: 'null'
    default: null
    description: Only take the description up to this terminating string. e.g. if
      you only want to take the first line of a multi-line description, set this to
      '\n'
SetDataType:
  overwrite:
    default: true
    description: Whether to overwrite existing properties with properties from the
      database. When false, keeps the values already present in the properties if
      present.
    type: boolean
Example
generator:
  exclude:
  - data_type
  - description
  description:
    overwrite: false
    terminator: .
  data_type:
    overwrite: true

You may also define the parameters for exclude directly on the definition like below.

generator: data_type