WMS_MAIN/database/migrations/20260506103000-add-box-fields-to-wms_receiving_detail.js
liufumingren d711ba9c21 0506更新
Co-authored-by: Copilot <copilot@github.com>
2026-05-06 17:53:54 +08:00

54 lines
1.7 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';
/**
* Migration: add box_remainder and box_weight to wms_receiving_detail
* - box_remainder: INT NOT NULL DEFAULT 0 COMMENT '箱余数'
* - box_weight: DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '箱重量(kg)'
*
* Idempotent: uses queryInterface.describeTable to only add if missing.
*
* Raw SQL (MySQL 8+ supports IF NOT EXISTS):
* ALTER TABLE `wms_receiving_detail`
* ADD COLUMN IF NOT EXISTS `box_remainder` INT NOT NULL DEFAULT 0 COMMENT '箱余数',
* ADD COLUMN IF NOT EXISTS `box_weight` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '箱重量(kg`)';
*
* If MySQL < 8 (no IF NOT EXISTS), use INFORMATION_SCHEMA checks before ALTER.
*/
module.exports = {
up: async (queryInterface, Sequelize) => {
const table = 'wms_receiving_detail';
const columns = await queryInterface.describeTable(table);
if (!columns.box_remainder) {
await queryInterface.addColumn(table, 'box_remainder', {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
comment: '箱余数',
});
}
if (!columns.box_weight) {
await queryInterface.addColumn(table, 'box_weight', {
type: Sequelize.DECIMAL(10, 2),
allowNull: false,
defaultValue: '0.00',
comment: '箱重量(kg)',
});
}
},
down: async (queryInterface, Sequelize) => {
const table = 'wms_receiving_detail';
const columns = await queryInterface.describeTable(table);
if (columns.box_remainder) {
await queryInterface.removeColumn(table, 'box_remainder');
}
if (columns.box_weight) {
await queryInterface.removeColumn(table, 'box_weight');
}
},
};