cli icon indicating copy to clipboard operation
cli copied to clipboard

Validators for Data Types

Open ZoeAde opened this issue 11 years ago • 8 comments

You should not be able to enter data types that do not exist in Sequelize.

node_modules/.bin/sequelize model:create --name Todo --attributes "name:RYANGOSLING"

Results in:

'use strict';
module.exports = {
  up: function(queryInterface, Sequelize) {
    return queryInterface.createTable('Todos', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      name: {
        type: Sequelize.RYANGOSLING
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  down: function(queryInterface, Sequelize) {
    return queryInterface.dropTable('Todos');
  }
};

ZoeAde avatar Nov 13 '15 21:11 ZoeAde

:+1:

mjhea0 avatar Nov 15 '15 15:11 mjhea0

Yep. Good idea. Want to file a PR?

sdepold avatar Nov 16 '15 05:11 sdepold

Can we wait to see the result of this PR https://github.com/sequelize/cli/pull/223

mjhea0 avatar Nov 16 '15 13:11 mjhea0

Also, would you recommend using https://www.npmjs.com/package/yargs for validation?

mjhea0 avatar Nov 16 '15 14:11 mjhea0

Not sure tbh. Guess yargs is not the right tool for that. IIRC https://github.com/sequelize/cli/blob/master/lib/helpers/model-helper.js#L28 this should be the line where we have access to the attributes. split[1] should contain the data type

sdepold avatar Nov 17 '15 05:11 sdepold

@sushantdhiman My OS is windows and when I try to run test there are bunch of errors like: 9:5 error Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style

By the way I fixed it but I don't know how to test it. Could you please give me the links to learns how to test it. Thanks

AminTizdastAzar avatar Oct 08 '17 17:10 AminTizdastAzar

@sushantdhiman Can I work on this if no one is working on it?

pranavpr avatar Dec 13 '17 16:12 pranavpr

Fixed by https://github.com/sequelize/cli/pull/682

sushantdhiman avatar Aug 19 '18 16:08 sushantdhiman