SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
CREATE DATABASE `resource_management` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;

USE `resource_management`;

-- ----------------------------
-- Table structure for machine_env
-- ----------------------------
DROP TABLE IF EXISTS `machine_env`;
CREATE TABLE `machine_env`  (
                                `id` bigint NOT NULL AUTO_INCREMENT,
                                `create_date` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
                                `update_date` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
                                `machine_id` bigint NULL DEFAULT NULL,
                                `env_key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                `env_value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                `sensitive` tinyint(1) NULL DEFAULT NULL COMMENT '是否敏感（0=false, 1=true, NULL=未设置）', -- 改为 tinyint 存储布尔值
                                `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                PRIMARY KEY (`id`) USING BTREE,
                                UNIQUE KEY `uk_machine_env_key` (`machine_id`, `env_key`) -- 同一机器下 env_key 唯一
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for machine_info
-- ----------------------------
DROP TABLE IF EXISTS `machine_info`;
CREATE TABLE `machine_info`  (
                                 `id` bigint NOT NULL AUTO_INCREMENT,
                                 `create_date` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
                                 `update_date` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
                                 `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                 `tag` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                 `host_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                 `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                 `status_code` int NULL DEFAULT NULL COMMENT '状态编码（关联字典表）', -- 改为 int 类型
                                 `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                 `ssh_port` int NULL DEFAULT NULL COMMENT 'SSH端口号（整数）', -- 改为 int 类型
                                 `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                 `secret_key_id` bigint NULL DEFAULT NULL COMMENT '密钥ID（逻辑关联，无外键）',
                                 `machine_proxy_id` bigint NULL DEFAULT NULL COMMENT '代理ID（逻辑关联，无外键）',
                                 `authentication_type_code` int NULL DEFAULT NULL COMMENT '认证类型编码',
                                 PRIMARY KEY (`id`) USING BTREE,
                                 KEY `idx_secret_key_id` (`secret_key_id`), -- 保留索引优化查询
                                 KEY `idx_machine_proxy_id` (`machine_proxy_id`)
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for machine_proxy
-- ----------------------------
DROP TABLE IF EXISTS `machine_proxy`;
CREATE TABLE `machine_proxy`  (
                                  `id` bigint NOT NULL AUTO_INCREMENT,
                                  `create_date` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
                                  `update_date` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
                                  `host_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                  `ssh_port` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                  `proxy_type_code` int NULL DEFAULT NULL COMMENT '代理类型编码（关联字典表）',
                                  `version` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                  `status_code` int NULL DEFAULT NULL COMMENT '状态编码（关联字典表）', -- 改为 int 类型
                                  `last_heart_beat_time` datetime(0) NULL DEFAULT NULL,
                                  `config` json NULL,
                                  `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for machine_secret_key
-- ----------------------------
DROP TABLE IF EXISTS `machine_secret_key`;
CREATE TABLE `machine_secret_key`  (
                                       `id` bigint NOT NULL AUTO_INCREMENT,
                                       `create_date` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
                                       `update_date` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
                                       `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                       `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                       `path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                       `file_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                       `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                       PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;