WMS_MAIN/database/migrations/20260718160000-split-camera-server-port.js
liufumingren b485f8e9f1 feat(camera): 新增摄像头/录制模块 (camera/camera_server/pack_task_video)
- 新增 model: camera, camera_server

- 新增 services: camera, cameraServer (systemMethods + systems)

- 新增 pack_task_video 表及录制状态管理

- 7 条迁移: 建表→设备字段→端口拆分→状态枚举
2026-07-27 03:46:51 +08:00

90 lines
3.3 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';
const TABLE_NAME = 'wms_camera_server';
/**
* 将 wms_camera_server.port 拆分为 public_port(远程/公网端口)和 internal_port(本地/内网端口)。
* 原因:远程访问端口和本地访问端口通常不同(如 NAT 映射),需要分别存储。
*/
module.exports = {
up: async (queryInterface, Sequelize) => {
const tableInfo = await queryInterface.describeTable(TABLE_NAME);
// 1. 添加 public_port
if (!tableInfo.public_port) {
await queryInterface.addColumn(TABLE_NAME, 'public_port', {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: true,
comment: '远程/公网端口',
after: 'internal_ip',
});
console.log('[Migration] wms_camera_server.public_port 已添加');
} else {
console.log('[Migration] wms_camera_server.public_port 已存在,跳过');
}
// 2. 添加 internal_port
if (!tableInfo.internal_port) {
await queryInterface.addColumn(TABLE_NAME, 'internal_port', {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: true,
comment: '本地/内网端口',
after: 'public_port',
});
console.log('[Migration] wms_camera_server.internal_port 已添加');
} else {
console.log('[Migration] wms_camera_server.internal_port 已存在,跳过');
}
// 3. 将旧 port 数据迁移到 public_port 和 internal_port(保留旧值,后续可按需调整)
if (tableInfo.port) {
await queryInterface.sequelize.query(
`UPDATE ${TABLE_NAME} SET public_port = port, internal_port = port WHERE port IS NOT NULL`
);
console.log('[Migration] wms_camera_server.port 数据已复制到 public_port 和 internal_port');
// 4. 删除旧 port 列
await queryInterface.removeColumn(TABLE_NAME, 'port');
console.log('[Migration] wms_camera_server.port 列已删除');
} else {
console.log('[Migration] wms_camera_server.port 列不存在,跳过迁移和删除');
}
},
down: async (queryInterface, Sequelize) => {
const tableInfo = await queryInterface.describeTable(TABLE_NAME);
// 恢复 port 列
if (!tableInfo.port) {
await queryInterface.addColumn(TABLE_NAME, 'port', {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: true,
defaultValue: 80,
comment: '端口号',
after: 'internal_ip',
});
console.log('[Migration] wms_camera_server.port 列已恢复');
}
// 将 public_port 数据回写到 port(优先使用 internal_port)
if (tableInfo.public_port || tableInfo.internal_port) {
await queryInterface.sequelize.query(
`UPDATE ${TABLE_NAME} SET port = COALESCE(internal_port, public_port) WHERE internal_port IS NOT NULL OR public_port IS NOT NULL`
);
console.log('[Migration] port 数据已从 public_port/internal_port 回写');
}
// 删除 public_port
if (tableInfo.public_port) {
await queryInterface.removeColumn(TABLE_NAME, 'public_port');
console.log('[Migration] wms_camera_server.public_port 列已删除');
}
// 删除 internal_port
if (tableInfo.internal_port) {
await queryInterface.removeColumn(TABLE_NAME, 'internal_port');
console.log('[Migration] wms_camera_server.internal_port 列已删除');
}
},
};