37848-vm/backend/src/db/models/sandboxes.js
2026-01-26 19:53:36 +00:00

135 lines
1.7 KiB
JavaScript

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 sandboxes = sequelize.define(
'sandboxes',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
platform: {
type: DataTypes.ENUM,
values: [
"linux",
"windows",
"macos"
],
},
endpoint: {
type: DataTypes.TEXT,
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
heartbeat: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
sandboxes.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.sandboxes.hasMany(db.analyses, {
as: 'analyses_sandbox',
foreignKey: {
name: 'sandboxId',
},
constraints: false,
});
//end loop
db.sandboxes.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.sandboxes.belongsTo(db.users, {
as: 'createdBy',
});
db.sandboxes.belongsTo(db.users, {
as: 'updatedBy',
});
};
return sandboxes;
};