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

69 lines
1.3 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Consumable = sequelize.define('Consumable', {
consumableId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
category: {
type: DataTypes.STRING,
allowNull: false
},
unit: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: '个'
},
currentStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
minStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 10
},
maxStock: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 100
},
unitPrice: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
defaultValue: 0
},
supplier: {
type: DataTypes.STRING
},
location: {
type: DataTypes.STRING,
comment: '存放位置'
},
description: {
type: DataTypes.TEXT
},
status: {
type: DataTypes.STRING,
defaultValue: 'active'
}
}, {
tableName: 'consumables',
timestamps: true,
indexes: [
{ fields: ['category'] },
{ fields: ['status'] },
{ fields: ['category', 'status'] }
]
});
module.exports = Consumable;