56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
'use strict';
|
||
|
||
const TABLE_NAME = 'wms_camera';
|
||
|
||
/**
|
||
* 新增摄像头设备信息字段:IP、SDK端口、型号、序列号、码流类型。
|
||
* 用于保存 NVR 服务器返回的摄像头详细设备信息。
|
||
*/
|
||
module.exports = {
|
||
up: async (queryInterface, Sequelize) => {
|
||
const columns = [
|
||
{
|
||
name: 'ip',
|
||
def: { type: Sequelize.STRING(50), allowNull: true, comment: '摄像头IP地址', after: 'channel_name' },
|
||
},
|
||
{
|
||
name: 'port',
|
||
def: { type: Sequelize.INTEGER.UNSIGNED, allowNull: true, comment: 'SDK管理端口(通常2020/8000)', after: 'ip' },
|
||
},
|
||
{
|
||
name: 'model',
|
||
def: { type: Sequelize.STRING(100), allowNull: true, comment: '摄像头型号', after: 'port' },
|
||
},
|
||
{
|
||
name: 'serial_number',
|
||
def: { type: Sequelize.STRING(100), allowNull: true, comment: '摄像头序列号', after: 'model' },
|
||
},
|
||
{
|
||
name: 'stream_type',
|
||
def: { type: Sequelize.STRING(20), allowNull: true, comment: '码流类型(auto/main/sub)', after: 'serial_number' },
|
||
},
|
||
];
|
||
|
||
for (const col of columns) {
|
||
const tableInfo = await queryInterface.describeTable(TABLE_NAME);
|
||
if (!tableInfo[col.name]) {
|
||
await queryInterface.addColumn(TABLE_NAME, col.name, col.def);
|
||
console.log(`[Migration] wms_camera.${col.name} 已添加`);
|
||
} else {
|
||
console.log(`[Migration] wms_camera.${col.name} 已存在,跳过`);
|
||
}
|
||
}
|
||
},
|
||
|
||
down: async queryInterface => {
|
||
const columns = [ 'stream_type', 'serial_number', 'model', 'port', 'ip' ];
|
||
for (const col of columns) {
|
||
const tableInfo = await queryInterface.describeTable(TABLE_NAME);
|
||
if (tableInfo[col]) {
|
||
await queryInterface.removeColumn(TABLE_NAME, col);
|
||
console.log(`[Migration] wms_camera.${col} 已移除`);
|
||
}
|
||
}
|
||
},
|
||
};
|