Update validation without replacing
We have conditional migrations that run under feature flags. Some of these migrations need to add the optional models to validation rules for other models. Currently .validations() replaces all the validation rules which makes it hard when dealing with multiple conditional models.
Our current solution is to have "validation migrations" for each model that run 100% of the time, after all of the conditional migrations. E.g. for the page model:
module.exports = function (migration) {
migration
.editContentType('page')
.editField('exampleField')
.items({
type: 'Link',
validations: [
{
linkContentType: [
'modelOne',
'modelTwo',
...(process.env.MODEL_THREE_ENABLED === 'true' ? ['conditionalModelThree'] : []),
...(process.env.MODEL_FOUR_ENABLED === 'true' ? ['conditionalModelFour'] : []),
],
},
],
linkType: 'Entry',
})
}
Are there any plans to add an updateValidations method that fetches the existing vaidation rules and adds new rules rather than replacing the whole set of rules? I'm not sure how this would work with .items() but please let me know if you have a better solution that what we are doing now.
Hi @bradley-varol,
we currently have not planned anything in this direction, but I'm happy to create a feature request for it. Also - please feel free to open a pull request and ping me!