WMS_MAIN/database/migrations/20260606042732-add-auto-increment-to-wms-order-items-partitions.js
liufumingren 99367e5043 1
2026-06-06 05:15:46 +08:00

50 lines
1.4 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';
/**
* 修复 wms_order_items 分表的 id 列缺少 AUTO_INCREMENT 的问题。
*
* 背景:sync({ alter: true }) 修了所有字段但没有检测到 id 缺少 AUTO_INCREMENT,
* 需要手动为以下分表补充:
* - wms_order_items_100000_dispatch
* - wms_order_items_100000_history
* - wms_order_items_1000028
*
* @param {import('sequelize').QueryInterface} queryInterface
* @param {import('sequelize')} Sequelize
* @return {Promise<void>}
*/
module.exports.up = async (queryInterface, Sequelize) => {
const tables = [
'wms_order_items_100000_dispatch',
'wms_order_items_100000_history',
'wms_order_items_1000028',
];
for (const table of tables) {
await queryInterface.sequelize.query(
`ALTER TABLE \`${table}\` MODIFY id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT`
);
}
};
/**
* 回滚:移除 AUTO_INCREMENT(恢复为普通 BIGINT UNSIGNED NOT NULL)。
*
* @param {import('sequelize').QueryInterface} queryInterface
* @param {import('sequelize')} Sequelize
* @return {Promise<void>}
*/
module.exports.down = async (queryInterface, Sequelize) => {
const tables = [
'wms_order_items_100000_dispatch',
'wms_order_items_100000_history',
'wms_order_items_1000028',
];
for (const table of tables) {
await queryInterface.sequelize.query(
`ALTER TABLE \`${table}\` MODIFY id BIGINT UNSIGNED NOT NULL`
);
}
};