- 新增模型 wms_warehouse_front_config 与迁移:建表、 追加 favicon_url、追加 cert_pem(可回滚) - systems/setting/warehouse.js 实现 getFrontConfig / saveFrontConfig / saveFrontCert、 域名唯一性校验、按域名缓存读取(含未登记域名的短 TTL 空缓存防穿透)与缓存清理 - systemMethods/setting/warehouse.js 开放对应 system method - 新增公共免登录接口 frontConfig.getByDomain:按域名返回公开字段 (domain/title/logo_url/login_bg_url/favicon_url/theme), 不返回 cert_path/key_path/sync_status 等内部字段;未登记域名返回 404
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
'use strict';
|
||
|
||
const TABLE_NAME = 'wms_warehouse_front_config';
|
||
const COLUMN_NAME = 'favicon_url';
|
||
|
||
/**
|
||
* 判断表是否存在。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {string} tableName 表名。
|
||
* @return {Promise<boolean>} 存在返回 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<void>} 无返回值。
|
||
*/
|
||
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<void>} 无返回值。
|
||
*/
|
||
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);
|
||
},
|
||
};
|