oms/backend/database/migrations/20260909000103-create-products.js

57 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/** 4. 商品表:普通商品,归属于具体主体 */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable(
'products',
{
id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
principal_id: {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: false,
comment: '所属主体ID',
references: { model: 'principals', key: 'id' },
},
code: { type: Sequelize.STRING(50), allowNull: false, comment: '商品编码' },
name: { type: Sequelize.STRING(100), allowNull: false, comment: '商品名称' },
type: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '商品类型' },
category: { type: Sequelize.STRING(50), allowNull: true, comment: '分类' },
spec: { type: Sequelize.STRING(100), allowNull: true, comment: '规格' },
unit: { type: Sequelize.STRING(20), allowNull: true, comment: '单位' },
price: { type: Sequelize.DECIMAL(12, 2), allowNull: false, defaultValue: 0, comment: '销售价' },
cost_price: { type: Sequelize.DECIMAL(12, 2), allowNull: true, comment: '成本价' },
image: { type: Sequelize.STRING(255), allowNull: true, comment: '图片' },
status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1上架 0下架' },
remark: { type: Sequelize.STRING(255), allowNull: true, comment: '备注' },
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
},
},
{ charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '商品表' }
);
await queryInterface.addIndex('products', {
fields: [ 'principal_id', 'code' ],
unique: true,
name: 'uk_products_principal_code',
});
},
async down(queryInterface) {
await queryInterface.dropTable('products');
},
};