const config = require('../../config'); const providers = config.providers; const crypto = require('crypto'); const bcrypt = require('bcrypt'); const moment = require('moment'); module.exports = function(sequelize, DataTypes) { const ml_models = sequelize.define( 'ml_models', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, name: { type: DataTypes.TEXT, }, model_family: { type: DataTypes.ENUM, values: [ "phishing_nlp", "url_classifier", "malware_static", "malware_behavior", "ensemble" ], }, framework: { type: DataTypes.ENUM, values: [ "tensorflow", "pytorch", "scikit_learn", "onnx" ], }, task_description: { type: DataTypes.TEXT, }, storage_uri: { type: DataTypes.TEXT, }, checksum: { type: DataTypes.TEXT, }, supports_local_inference: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, lifecycle_stage: { type: DataTypes.ENUM, values: [ "development", "staging", "production", "deprecated" ], }, released_at: { type: DataTypes.DATE, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); ml_models.associate = (db) => { /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity db.ml_models.hasMany(db.model_versions, { as: 'model_versions_model', foreignKey: { name: 'modelId', }, constraints: false, }); //end loop db.ml_models.belongsTo(db.organizations, { as: 'organizations', foreignKey: { name: 'organizationsId', }, constraints: false, }); db.ml_models.belongsTo(db.users, { as: 'createdBy', }); db.ml_models.belongsTo(db.users, { as: 'updatedBy', }); }; return ml_models; };