44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
'use strict';
|
||
|
||
const TABLE_NAME = 'wms_camera';
|
||
|
||
/**
|
||
* 新增摄像头认证字段:username(用户名)、password(密码)。
|
||
* 用于保存摄像头登录认证信息。
|
||
*/
|
||
module.exports = {
|
||
up: async (queryInterface, Sequelize) => {
|
||
const columns = [
|
||
{
|
||
name: 'username',
|
||
def: { type: Sequelize.STRING(100), allowNull: true, comment: '摄像头登录用户名', after: 'stream_type' },
|
||
},
|
||
{
|
||
name: 'password',
|
||
def: { type: Sequelize.STRING(100), allowNull: true, comment: '摄像头登录密码', after: 'username' },
|
||
},
|
||
];
|
||
|
||
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 = [ 'password', 'username' ];
|
||
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} 已回滚删除`);
|
||
}
|
||
}
|
||
},
|
||
};
|