WMS_MAIN/database/migrations/archive/20260409120000-add-snapshot-columns-to-wms-stock-transaction.js

64 lines
1.5 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
const { INTEGER } = Sequelize;
const tableName = 'wms_stock_transaction';
const tableInfo = await queryInterface.describeTable(tableName);
const columns = [
[ 'before_quantity', {
type: INTEGER(12),
allowNull: true,
comment: '变更前总库存数量',
}],
[ 'after_quantity', {
type: INTEGER(12),
allowNull: true,
comment: '变更后总库存数量',
}],
[ 'before_locked_quantity', {
type: INTEGER(12),
allowNull: true,
comment: '变更前锁定数量',
}],
[ 'after_locked_quantity', {
type: INTEGER(12),
allowNull: true,
comment: '变更后锁定数量',
}],
];
for (const [ columnName, columnDefinition ] of columns) {
if (tableInfo[columnName]) {
continue;
}
await queryInterface.addColumn(tableName, columnName, columnDefinition);
}
},
async down(queryInterface) {
const tableName = 'wms_stock_transaction';
const tableInfo = await queryInterface.describeTable(tableName).catch(() => null);
if (!tableInfo) {
return;
}
const columns = [
'after_locked_quantity',
'before_locked_quantity',
'after_quantity',
'before_quantity',
];
for (const columnName of columns) {
if (!tableInfo[columnName]) {
continue;
}
await queryInterface.removeColumn(tableName, columnName);
}
},
};