Files
yunrui_asset/backend/models/Rack.js
T
zhang1106 a2f0032bad feat: 添加数据库索引优化查询性能
refactor(前端): 使用useMemo和useCallback优化性能
perf(后端): 优化统计查询性能
style: 统一前端样式定义
build: 添加创建索引脚本
2026-01-20 14:31:20 +08:00

55 lines
1.1 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Room = require('./Room');
const Rack = sequelize.define('Rack', {
rackId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
height: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 42 // 标准机柜高度(U数)
},
maxPower: {
type: DataTypes.FLOAT,
allowNull: false
},
currentPower: {
type: DataTypes.FLOAT,
defaultValue: 0
},
status: {
type: DataTypes.STRING,
defaultValue: 'active'
},
roomId: {
type: DataTypes.STRING,
allowNull: false,
references: {
model: Room,
key: 'roomId'
}
}
}, {
tableName: 'racks',
timestamps: true,
indexes: [
{ fields: ['roomId'] },
{ fields: ['status'] },
{ fields: ['roomId', 'status'] }
]
});
// 关联关系
Rack.belongsTo(Room, { foreignKey: 'roomId' });
Room.hasMany(Rack, { foreignKey: 'roomId' });
module.exports = Rack;