Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize: Change "validate" meta data of column

Is it possible to change the "validate" meta data of a column using a migration file? I tried the queryInterface.changeColumn method and it seems like it can only change the three meta data mentioned in the docs (defaultValue, allowNull, and type).

I've tried doing something like this inside the 'up' object of the migration file:

queryInterface.changeColumn(
  'tableName',
  'columnName',
  {
    validate: {
      is: /new_regex_validation/
    }
  }
)

However, the above attempt did not work for me when I ran "sequelize db:migrate"

For simplicity's sake, I'll use a table definition to elaborate on my question:

I'm trying to change an already existing table like this:

var tableName = sequelize.define('tableName', {
    columnName: {
        type: DataTypes.STRING,
        unique: true,
        allowNull: false,
        validate: {
            is: /some_regex_validation/
        }
    }
})

into this using sequelize migration:

var tableName = sequelize.define('tableName', {
    columnName: {
        type: DataTypes.STRING,
        unique: true,
        allowNull: false,
        validate: {
            is: /a_new-or-different_regex_validation/
        }
    }
})

or simply remove the validate meta data while using sequelize migration:

var tableName = sequelize.define('tableName', {
    columnName: {
        type: DataTypes.STRING,
        unique: true,
        allowNull: false
    }
})

Any ideas?

like image 953
JV Estolas Avatar asked Oct 02 '16 00:10

JV Estolas


1 Answers

Validation happens on the client, not on the database. You don't need a migration for it.

like image 150
felixfbecker Avatar answered Oct 14 '22 07:10

felixfbecker