WMS_MAIN/database/migrations/20260715220000-create-wms-camera-server.js

99 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_server';
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',
},
name: {
type: Sequelize.STRING(100),
allowNull: false,
comment: '服务器名称',
},
brand: {
type: Sequelize.STRING(50),
allowNull: true,
comment: '品牌(如 Hikvision/Dahua)',
},
public_ip: {
type: Sequelize.STRING(50),
allowNull: true,
comment: '公网IP',
},
internal_ip: {
type: Sequelize.STRING(50),
allowNull: true,
comment: '内网IP',
},
port: {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: true,
defaultValue: 80,
comment: '端口号',
},
username: {
type: Sequelize.STRING(100),
allowNull: true,
comment: '登录账号',
},
password: {
type: Sequelize.STRING(200),
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, [ 'status' ], { name: 'idx_status' });
await queryInterface.addIndex(TABLE_NAME, [ 'deleted_at' ], { name: 'idx_deleted_at' });
},
down: async queryInterface => {
await queryInterface.dropTable(TABLE_NAME);
},
};