Fixed model validation erroneously triggering on non-nullable text fields

refs https://github.com/TryGhost/Toolbox/issues/309

- I've just ran into a problem when deleting the `defaultTo` field on a
  non-nullable `text` column in our schema because this validation
  thinks there should be a value set
- `text` fields cannot have defaults so the schema is incorrect, and the
  validation triggering is a bug that's preventing it from being
  cleaned up
- the default is defined on the model so I don't think we're losing
  anything here
This commit is contained in:
Daniel Lockyer 2022-05-05 14:46:50 +01:00
parent 002cf5b0eb
commit 51498abb5c
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD

View File

@ -45,6 +45,8 @@ function validateSchema(tableName, model, options) {
// check nullable
if (Object.prototype.hasOwnProperty.call(schema[tableName][columnKey], 'nullable') &&
schema[tableName][columnKey].nullable !== true &&
Object.prototype.hasOwnProperty.call(schema[tableName][columnKey], 'type') &&
schema[tableName][columnKey].type !== 'text' &&
!Object.prototype.hasOwnProperty.call(schema[tableName][columnKey], 'defaultTo')
) {
if (validator.isEmpty(strVal)) {