Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to ignore item validation errors when value is unchanged #33

Closed
OldSneerJaw opened this issue Jun 13, 2018 · 1 comment
Closed
Assignees
Labels
enhancement New feature or request

Comments

@OldSneerJaw
Copy link
Owner

OldSneerJaw commented Jun 13, 2018

Feature Request

Description

Occasionally, when updating document definitions, it is necessary to introduce a breaking change to the schema. However, if there are already documents in the database that conform to the old schema but not the new schema (e.g. a string's regexPattern or an integer's minimumValue have changed), this can require a full, complicated data migration to the new format that may result in revision conflicts if any of the documents in question also happen to have been modified by an offline client. Sometimes this is unavoidable, but in other cases it is acceptable to "grandfather" the old value in for existing documents (e.g. a product ID format that is no longer used for new products, but is still valid for old, obsolete products).

This feature would introduce a new universal item validation constraint (e.g. skipValidationWhenValueUnchanged) that suppresses validation errors for that property/element when replacing a document revision where the corresponding property/element has the same semantic value. Also introduce a constraint that requires strict equality (e.g. skipValidationWhenValueUnchangedStrict).

Examples

Consider the following document definition:

myDoc: {
  typeFilter: simpleTypeFilter,
  authorizedRoles: { write: 'write' },
  propertyValidators: {
    code: {
      type: 'string',
      regexPattern: /^[a-z]{4}-\d{3}$/,
      skipValidationWhenValueUnchanged: true
    },
    quantity: {
      type: 'integer',
      required: true,
      minimumValue: 0
    }
  }
}

The code property must be four lowercase letters, followed by a dash and three digits. However, if the previous version of the code property's regexPattern expected only two digits at the end, then values from existing documents that match that regular expression would be invalid if not for the skipValidationWhenValueUnchanged option.

Therefore with a previous document body of { "code": "abcd-12", "quantity": 5 }, the following new document revision would be considered valid even though it validates the updated regexPattern for code: { "code": "abcd-12", "quantity": 4 }

@OldSneerJaw OldSneerJaw added the enhancement New feature or request label Jun 13, 2018
@OldSneerJaw OldSneerJaw self-assigned this Jul 4, 2018
OldSneerJaw added a commit that referenced this issue Jul 4, 2018
…ally equal value

Introduces the `skipValidationWhenValueUnchanged` constraint for all validation types. When enabled, validation is not performed on the property or element when it semantically equals the value from the previous revision (e.g. a `datetime` of "2018-06-13T18:01-07:00" is semantically equal to "2018-06-13T21:01-04:00"). The result is that, even if the property or element no longer satisfies the item constraint(s), its value will be allowed if it has not changed.
OldSneerJaw added a commit that referenced this issue Jul 4, 2018
… equal value

Introduces the `skipValidationWhenValueUnchangedStrict` constraint for all validation types. When enabled, validation is not performed on a property or element when it _strictly_ equals the value from the previous revision (e.g. a `datetime` of "2018-06-13T18:01-07:00" is not strictly equal to "2018-06-13T21:01-04:00" even though they refer to the same point in time). The result is that, even if the property or element no longer satisfies the item constraint(s), its value will be allowed if it has not changed at all.
@dkichler
Copy link
Collaborator

Addressed by #35 and #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants