You can add the db check contraint in the type
attribute of the column definition.
sequelize
sequelize.define(
'products',
{
price: {
type: 'numeric CHECK (price > 0)',
...
},
},
)
sequelize-typescript
@Column({
type: 'numeric CHECK (price > 0)', // instead of DataType.NUMBER
...
})
declare price: number
You can also add them using migrations. See: https://stackoverflow.com/a/51076516/6192751
You can also use js validations to accomplish this on the client side. See: https://github.com/sequelize/sequelize-typescript/issues/576#issuecomment-485383173