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

Update validation without replacing #1166

Open
bradley-varol opened this issue Jan 11, 2023 · 1 comment
Open

Update validation without replacing #1166

bradley-varol opened this issue Jan 11, 2023 · 1 comment

Comments

@bradley-varol
Copy link

bradley-varol commented Jan 11, 2023

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.

@marcolink
Copy link
Member

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!

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

No branches or pull requests

2 participants