WMS_MAIN/database/migrations/20260522133000-add-custom-name-to-wms-shops.js
liufumingren dc4894cb6d 1
2026-05-25 17:08:56 +08:00

43 lines
1.3 KiB
JavaScript

'use strict';
/**
* 为店铺表新增自定义名称字段。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
* @param {import('sequelize')} Sequelize Sequelize 实例
* @return {Promise<void>} 无返回值
*/
module.exports = {
/**
* 执行迁移:新增店铺自定义名称字段(幂等)。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
* @param {import('sequelize')} Sequelize Sequelize 实例
* @return {Promise<void>} 无返回值
*/
async up(queryInterface, Sequelize) {
const tableName = 'wms_shops';
const columns = await queryInterface.describeTable(tableName);
if (!columns.custom_name) {
await queryInterface.addColumn(tableName, 'custom_name', {
type: Sequelize.STRING(100),
allowNull: true,
comment: '店铺自定义名称',
});
}
},
/**
* 回滚迁移:删除店铺自定义名称字段(幂等)。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
* @return {Promise<void>} 无返回值
*/
async down(queryInterface) {
const tableName = 'wms_shops';
const columns = await queryInterface.describeTable(tableName);
if (columns.custom_name) {
await queryInterface.removeColumn(tableName, 'custom_name');
}
},
};