const { DataTypes } = require('sequelize'); const { sequelize } = require('../config/db'); const Product = sequelize.define('Product', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, comment: '商品ID' }, name: { type: DataTypes.STRING(100), allowNull: false, comment: '商品名称' }, description: { type: DataTypes.TEXT, allowNull: true, comment: '商品描述' }, price: { type: DataTypes.DECIMAL(10, 2), allowNull: false, comment: '商品价格' }, stock: { type: DataTypes.INTEGER, defaultValue: 0, comment: '库存数量' }, category: { type: DataTypes.STRING(50), allowNull: true, comment: '商品分类' }, imageUrl: { type: DataTypes.STRING(255), allowNull: true, comment: '商品图片URL' }, status: { type: DataTypes.TINYINT, defaultValue: 1, comment: '状态:1-上架,0-下架' }, createdAt: { type: DataTypes.DATE, allowNull: false, comment: '创建时间' }, updatedAt: { type: DataTypes.DATE, allowNull: false, comment: '更新时间' } }, { tableName: 'products', timestamps: false, underscored: true, // 自动将驼峰命名转换为下划线命名 paranoid: false, charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', freezeTableName: true, syncOnAssociation: false, }); module.exports = Product;