'use strict'; const TABLE_NAME = 'wms_warehouse_front_config'; const COLUMN_NAME = 'favicon_url'; /** * 判断表是否存在。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {string} tableName 表名。 * @return {Promise} 存在返回 true。 */ async function tableExists(queryInterface, tableName) { const tables = await queryInterface.showAllTables(); return tables.some(t => (typeof t === 'string' ? t : (t.tableName || t.name)) === tableName); } module.exports = { /** * 执行正向迁移:为仓库前端配置表新增 favicon_url(站点 favicon 图标地址,幂等)。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {import('sequelize')} Sequelize Sequelize 实例。 * @return {Promise} 无返回值。 */ async up(queryInterface, Sequelize) { if (!(await tableExists(queryInterface, TABLE_NAME))) { return; } const columns = await queryInterface.describeTable(TABLE_NAME); if (columns[COLUMN_NAME]) { return; } await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, { type: Sequelize.STRING(255), allowNull: true, comment: '站点 favicon 图标地址', }); }, /** * 回滚迁移:删除 favicon_url 字段(幂等)。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @return {Promise} 无返回值。 */ async down(queryInterface) { if (!(await tableExists(queryInterface, TABLE_NAME))) { return; } const columns = await queryInterface.describeTable(TABLE_NAME); if (!columns[COLUMN_NAME]) { return; } await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME); }, };