oms/backend/database/migrations/20260916001200-create-product-units.js
liufumingren d22f3e1f0a feat(backend): 新增商品分类/品牌/单位字典与属性菜单
- 按主体隔离的分类/品牌/单位 CRUD 与 /select 下拉接口
- 商品模型增加 brand_id / unit_id,属性被商品引用时禁止删除(attributeUsage)
- 迁移:建三张字典表、商品表加字段、种子属性菜单、is_system 保护内置项

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-30 23:06:09 +08:00

46 lines
1.9 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';
/**
* 商品单位字典表:product_units
* 定位:按主体隔离(principal_id),供商品选择「单位」时落 unit_id + stock_unit(单位文本)。
* 同一主体下单位名称唯一(uk_product_units_principal_name),名称即展示文本。
*/
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable(
'product_units',
{
id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true },
principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
name: { type: Sequelize.STRING(100), allowNull: false, comment: '单位名称' },
code: { type: Sequelize.STRING(50), allowNull: true, comment: '单位编码' },
status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
sort: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0, comment: '排序(下拉展示顺序,越小越靠前)' },
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('product_units', {
fields: [ 'principal_id', 'name' ],
unique: true,
name: 'uk_product_units_principal_name',
});
await queryInterface.addIndex('product_units', { fields: [ 'principal_id', 'status', 'sort' ], name: 'idx_product_units_p_s_sort' });
},
async down(queryInterface) {
await queryInterface.dropTable('product_units');
},
};