54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
'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');
|
||
}
|
||
},
|
||
};
|