Migration to @forestadmin/agent - min/max validations generated from sequelize models do not include the endpoints

Hi.
We’re migrating from forest-express-sequelize to @forestadmin/agent .

We have a sequelize model with an integer field with a max value defined in the model itself.

In the model we have max: 80 which acts as a <= and the new agent (while parsing the validations) puts a 'is less than' in the .forestadmin-schema.json file.

But now in the new agent forest admin panel, the value 80 is not accepted any more.

Here is the error shown in forest with the new agent:

NB: with the old agent the very same model used to work, correctly validating (including) the endpoint numbers: 80 <= 80.

Field definition in the sequelize model:

  ageTo: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: 'Max boundary (inclusive) for age restrictions',
    field: 'age_to',
    validate: {
      min: 0,
      max: 80,
    },
  },

In sequelize, the min/max values are included: Validations & Constraints | Sequelize
image (71)

May you please have a check about this?

Thank you.
Matteo

1 Like

Hello @Matteo :wave:

Thanks for your report.

Unfortunately, we don’t support LessThanEqual and GreaterThanEqual validators yet… I will have a look at adding them today.

In the meanwhile, I have made this tiny monkey patch.

I will let you know once we have more news about that.

Kind regards,
Morgan

1 Like

Hello @Matteo,

I’m happy to annonce that we rework the agent and the sequelize datasource in order to correctly support min/max sequelize validators.

To be capable of this we did add a new required feature (two new well known operators: GreaterThanOrEqual & LessThanOrEqual along side the same validators). It’s a nice improvement too to meet industry standards.

Example done with Sequelize

Sequelize model
sequelize.define('place', {
  name: DataTypes.STRING,
  address: DataTypes.STRING,
  latitude: {
    type: DataTypes.INTEGER,
    validate: {
      min: -90,
      max: 90,
    },
  },
  longitude: {
    type: DataTypes.INTEGER,
    validate: {
      min: -180,
      max: 180,
    },
  },
});

Screenshot 2024-09-27 at 11.48.40

You can upgrade to the latest @forestadmin/datasource-sequelize version and also bump to the latest @forestadmin/agent version.

Let’s us know if it works for you.

Kind regards,
Morgan

2 Likes

Thank you very much @morganperre,
as this is not the first time you pull the chestnuts out of the fire :smiley:

Your help and your responsiveness is greatly appreciated.
Thank you!
Matteo

1 Like

:joy: You’re welcome.

I hope that you will finalize the migration successfully. For sure, you help us improve the new agent with new features and more accurate behaviors.

Kind regards,
Morgan

1 Like