SET FOREIGN_KEY_CHECKS=0;

CREATE TABLE IF NOT EXISTS `ne_host` (
  `host_id` bigint NOT NULL AUTO_INCREMENT COMMENT '主机主键',
  `host_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '连接类型 ssh telnet redis',
  `group_id` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '分组（0默认 1网元 2系统）',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '标题名称',
  `addr` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '主机地址',
  `port` int DEFAULT '22' COMMENT '端口 22 4100 6379',
  `user` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '认证用户名',
  `auth_mode` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '认证模式（0密码 1主机私钥 2已免密）',
  `password` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '认证密码',
  `private_key` varchar(6000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '认证私钥',
  `pass_phrase` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '认证私钥密码',
  `db_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '数据库名称',
  `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '备注',
  `create_by` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '创建者',
  `create_time` bigint DEFAULT '0' COMMENT '创建时间',
  `update_by` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新者',
  `update_time` bigint DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`host_id`) USING BTREE,
  UNIQUE KEY `uk_type_group_title` (`host_type`,`group_id`,`title`) USING BTREE COMMENT '同组内名称唯一'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='网元主机表';

-- 20241016前旧表更新
ALTER TABLE `ne_host` ADD COLUMN IF NOT EXISTS `db_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '数据库名称' AFTER `pass_phrase`;
ALTER TABLE `ne_host` MODIFY COLUMN IF EXISTS `host_id` bigint NOT NULL COMMENT '主机主键' FIRST;
ALTER TABLE `ne_host` MODIFY COLUMN IF EXISTS `host_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '连接类型 ssh telnet redis' AFTER `host_id`;
ALTER TABLE `ne_host` MODIFY COLUMN IF EXISTS `port` int NULL DEFAULT 22 COMMENT '端口 22 4100 6379' AFTER `addr`;
ALTER TABLE `ne_host` MODIFY COLUMN IF EXISTS `user` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '认证用户名' AFTER `port`;
ALTER TABLE `ne_host` MODIFY COLUMN IF EXISTS `create_time` bigint NULL DEFAULT 0 COMMENT '创建时间' AFTER `create_by`;
ALTER TABLE `ne_host` MODIFY COLUMN IF EXISTS `update_time` bigint NULL DEFAULT 0 COMMENT '更新时间' AFTER `update_by`;
ALTER TABLE `ne_host` MODIFY COLUMN IF EXISTS `host_id` bigint NOT NULL AUTO_INCREMENT COMMENT '主机主键';

SET FOREIGN_KEY_CHECKS=1;
