From 51498abb5cb9cd0a07ed34aecab955fffd1be9b2 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 5 May 2022 14:46:50 +0100 Subject: [PATCH] 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 --- core/server/data/schema/validator.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/server/data/schema/validator.js b/core/server/data/schema/validator.js index c7bfac555b..9a660d0ac6 100644 --- a/core/server/data/schema/validator.js +++ b/core/server/data/schema/validator.js @@ -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)) {