datacontract / datacontract-specification

The Data Contract Specification Repository
https://datacontract.com/
MIT License
278 stars 41 forks source link

Add constraints to field object #17

Closed stefannegele closed 7 months ago

stefannegele commented 1 year ago

It would be nice to have the possibility to add field constraints to a Field Object because with the current state of the specification, the data contract cannot contain constraint (e.g. nullability) information on a field.

Since field existence (required or nullable) and uniqueness (unique) are so omnipresent and important, I would make them first level citizens in the field object. All other constraints can live in a field constraints similar to how dbt does it. My idea how to store such information in the contract is:

models:
  my_table:
    description: contains data
    fields:
      my_column:
        description: contains values
        type: text
        required: true # this is new
        unique: true # this is new
        constraints: # this is new
          primary_key_constraint:
            type: primary_key
          check_constraint:
            type: check
            expression: "my_column == my_column"
    type: table
stefannegele commented 12 months ago
models:
  my_table:
    description: contains data
    required:
      - primary_key
    unique:
      - primary_key
    constraints: # this is new
      model_constraint:
        type: check
        expression: "primary_key > 0"
    fields:
      my_column:
        description: contains values
        type: text
        constraints: # this is new
          primary_key_constraint:
            type: primary_key
          check_constraint:
            type: check
            expression: "my_column == my_column"
    type: table
jochenchrist commented 7 months ago

I think this is obsolete with the current formats and https://github.com/datacontract/datacontract-specification/issues/55