WMS_MAIN/database/migrations/20260715220001-create-wms-camera.js

89 lines
2.6 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';
module.exports = {
up: async (queryInterface, Sequelize) => {
const tables = await queryInterface.showAllTables();
const exists = tables.some(t => (typeof t === 'string' ? t : t.tableName) === TABLE_NAME);
if (exists) return;
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键ID',
},
warehouse_id: {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID',
},
server_id: {
type: Sequelize.BIGINT(20).UNSIGNED,
allowNull: false,
comment: '所属录像服务器ID,关联 wms_camera_server.id',
},
channel_id: {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: false,
comment: '通道编号(DVR/NVR 上的物理通道号)',
},
channel_name: {
type: Sequelize.STRING(100),
allowNull: true,
comment: '通道原始名称',
},
custom_name: {
type: Sequelize.STRING(100),
allowNull: true,
comment: '自定义摄像头名称',
},
status: {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 1,
comment: '状态:0-禁用 1-启用',
},
remark: {
type: Sequelize.STRING(500),
allowNull: true,
comment: '备注',
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
comment: '更新时间',
},
deleted_at: {
type: Sequelize.DATE,
allowNull: true,
comment: '软删除时间',
},
});
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id' ], { name: 'idx_warehouse_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'server_id' ], { name: 'idx_server_id' });
// 同一服务器下通道号唯一
await queryInterface.addIndex(TABLE_NAME, [ 'server_id', 'channel_id', 'deleted_at' ], {
unique: true,
name: 'uk_server_channel',
});
await queryInterface.addIndex(TABLE_NAME, [ 'status' ], { name: 'idx_status' });
await queryInterface.addIndex(TABLE_NAME, [ 'deleted_at' ], { name: 'idx_deleted_at' });
},
down: async queryInterface => {
await queryInterface.dropTable(TABLE_NAME);
},
};