sequelize/cli

Validators for Data Types

ZoeAde opened this issue · 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');
  }
};

👍

Yep. Good idea. Want to file a PR?

Can we wait to see the result of this PR #223

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

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

@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

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

Fixed by #682