Its probably best if i dont implement files that are in the sequelize module, that will make updates difficult, is there a way to implement my own Data Types file?
Thank you
Right, but im saying i shouldnt edit the libraries js files, that would mess with git updates. Is there a way to have my own data-types.js file included and used by sequelize, without messing with any sequelize files thenselves?..
table_name SET('a','b','c') NOT NULL
"use strict";
const CONFIG = require( '../config' );
const UTIL = require('util');
const SEQUELIZE = require( 'sequelize' );
/**
* Create the SET DataType, which has the same format as ENUM when creating tables, so
* this is basically the ENUM DataType code from here:
* https://github.com/sequelize/sequelize/blob/master/lib/data-types.js#L738-L761
* Just altered to be placed in here, independent of the Sequelize lib
*/
var SET = SEQUELIZE.ABSTRACT.inherits(function(value) {
var options = typeof value === 'object' && !Array.isArray(value) && value || {
values: Array.prototype.slice.call(arguments).reduce(function(result, element) {
return result.concat(Array.isArray(element) ? element : [element]);
}, [])
};
if (!(this instanceof SET)) return new SET(options);
this.values = options.values;
this.options = options;
});
SET.prototype.key = SET.key = 'SET';
SET.prototype.validate = function(value) {
if (!_.contains(this.values, value)) {
throw new Error(UTIL.format('ERROR: %j is not a valid choice in %j', value, this.values));
}
return true;
};
module.exports = function ( sequelize, DataTypes ) {
var _ = sequelize.Utils._;
var serversColumns = {
computerId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
field: 'computer_id'
},
hostname: {
type: DataTypes.STRING,
unique: true,
allowNull: false
},
operatingSystem: {
type: DataTypes.ENUM('rhel 4', 'rhel 5', 'rhel 6', 'centos 4', 'centos 5', 'centos 6'),
allowNull: false,
field: 'operating_system'
},
applications: {
type: SET('apache','nginx','nagios'),
allowNull: true
},
notes: {
type: DataTypes.TEXT,
allowNull: true
}
};
// Define the Sequelize model using the columns gathered above, and set any default settings
return sequelize.define( 'Computer', serversColumns, {
//freezeTableName: true,
tableName: 'computers',
//underscored: true,
paranoid: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
deletedAt: 'deleted_at'
}
);
}
CREATE TABLE IF NOT EXISTS `computers` (`computer_id` INTEGER NOT NULL auto_increment , `hostname` VARCHAR(255) NOT NULL UNIQUE, `operating_system` ENUM('rhel 4', 'rhel 5', 'rhel 6', 'centos 4', 'centos 5', 'centos 6') NOT NULL, `applications` SET, `notes` TEXT, `created_at` DATETIME NOT NULL, `updated_at` DATETIME NOT NULL, `deleted_at` DATETIME, PRIMARY KEY (`computer_id`)) ENGINE=InnoDB;