From d29fa8f2fa6e5f23d9462b438a3dd5cf29a4bb02 Mon Sep 17 00:00:00 2001
From: gongzt <gong_zhengtang@163.com>
Date: Mon, 25 Sep 2023 18:30:28 +0800
Subject: fix database type error
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 database/diana.sql            | 146 +++++++++++++++++-----------------
 diana/database/dao/app_dao.py |   4 +-
 2 files changed, 75 insertions(+), 75 deletions(-)

diff --git a/database/diana.sql b/database/diana.sql
index d4452c4..a251f21 100644
--- a/database/diana.sql
+++ b/database/diana.sql
@@ -1,88 +1,88 @@
 use aops;
 
 CREATE TABLE IF NOT EXISTS `domain_check_result` (
-    `alert_id`      CHAR(32)   NOT NULL, 
-    `domain`        CHAR(20)   NOT NULL, 
-    `alert_name`    CHAR(50)   NULL, 
-    `time`          INT(11)    NULL, 
-    `workflow_name` CHAR(50)   NULL, 
-    `workflow_id`   CHAR(32)   NULL, 
-    `username`      CHAR(20)   NULL, 
-    `level`         CHAR(20)   NULL, 
-    `confirmed`     TINYINT(1) NULL, 
-    PRIMARY KEY (`alert_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC ;
+  `alert_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `domain` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `alert_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  `time` int NOT NULL,
+  `workflow_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `workflow_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `username` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  `level` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  `confirmed` tinyint(1) NULL DEFAULT NULL,
+  PRIMARY KEY (`alert_id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 CREATE TABLE IF NOT EXISTS `alert_host` (
-    `alert_id`  CHAR(32) NOT NULL, 
-    `host_id`   CHAR(32) NOT NULL, 
-    `host_ip`   CHAR(32) NULL, 
-    `host_name` CHAR(50) NULL, 
-    PRIMARY KEY (`host_id`,`alert_id`), 
-    KEY `FK__alert_id_auto_index` (`alert_id`), 
-    KEY `FK_alert_with_host_host_id_auto_index` (`host_id`),
-    CONSTRAINT `FK_alert_host_alert_id` FOREIGN KEY (`alert_id`) REFERENCES `domain_check_result` (`alert_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC ;
+  `host_id` int NOT NULL,
+  `alert_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `host_ip` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `host_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  PRIMARY KEY (`host_id`, `alert_id`) USING BTREE,
+  INDEX `alert_id`(`alert_id`) USING BTREE,
+  CONSTRAINT `alert_host_ibfk_1` FOREIGN KEY (`alert_id`) REFERENCES `domain_check_result` (`alert_id`) ON DELETE CASCADE ON UPDATE RESTRICT
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 CREATE TABLE IF NOT EXISTS `algorithm` (
-    `algo_id`     INT(11)   NOT NULL, 
-    `path`        CHAR(150) NULL, 
-    `username`    CHAR(10)  NULL, 
-    `algo_name`   CHAR(20)  NOT NULL, 
-    `field`       CHAR(20)  NOT NULL, 
-    `description` LONGTEXT  NULL, 
-    PRIMARY KEY (`algo_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC ;
+    `algo_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+    `algo_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+    `field` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+    `description` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+    `path` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+    `username` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+    PRIMARY KEY (`algo_id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 CREATE TABLE IF NOT EXISTS `host_check_result` (
-    `id`           INT(11)    NOT NULL, 
-    `time`         INT(11)    NOT NULL, 
-    `is_root`      TINYINT(1) NULL, 
-    `host_id`      CHAR(32)   NOT NULL, 
-    `metric_name`  CHAR(50)   NULL, 
-    `alert_id`     CHAR(32)   NOT NULL, 
-    `metric_label` CHAR(255)  NULL, 
-    PRIMARY KEY (`id`), 
-    KEY `host_id_auto_index` (`host_id`), 
-    KEY `alert_id_auto_index` (`alert_id`),
-    CONSTRAINT `FK_host_check_result_host_id` FOREIGN KEY (`host_id`) REFERENCES `alert_host` (`host_id`) ON DELETE RESTRICT ON UPDATE RESTRICT , 
-    CONSTRAINT `FK_host_check_result_alert_id` FOREIGN KEY (`alert_id`) REFERENCES `domain_check_result` (`alert_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC ;
+  `id` int NOT NULL AUTO_INCREMENT,
+  `host_id` int NULL DEFAULT NULL,
+  `alert_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  `time` int NOT NULL,
+  `is_root` tinyint(1) NULL DEFAULT NULL,
+  `metric_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  `metric_label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  PRIMARY KEY (`id`) USING BTREE,
+  INDEX `host_id`(`host_id`) USING BTREE,
+  INDEX `alert_id`(`alert_id`) USING BTREE,
+  CONSTRAINT `host_check_result_ibfk_1` FOREIGN KEY (`host_id`) REFERENCES `alert_host` (`host_id`) ON DELETE CASCADE ON UPDATE RESTRICT,
+  CONSTRAINT `host_check_result_ibfk_2` FOREIGN KEY (`alert_id`) REFERENCES `domain_check_result` (`alert_id`) ON DELETE CASCADE ON UPDATE RESTRICT
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 CREATE TABLE IF NOT EXISTS `model` (
-    `model_id`    INT(11)   NOT NULL, 
-    `username`    CHAR(40)  NULL, 
-    `model_name`  CHAR(10)  NULL, 
-    `tag`         CHAR(255) NULL, 
-    `algo_id`     INT(11)   NULL, 
-    `create_time` INT(11)   NULL, 
-    `file_path`   CHAR(64)  NULL, 
-    `precision`   DOUBLE    NULL, 
-    PRIMARY KEY (`model_id`), 
-    KEY `algo_id_auto_index` (`algo_id`),
-    CONSTRAINT `FK_model_algo_id` FOREIGN KEY (`algo_id`) REFERENCES `algorithm` (`algo_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC ;
+  `model_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `model_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `tag` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  `algo_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `create_time` int NOT NULL,
+  `file_path` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  `precision` float NULL DEFAULT NULL,
+  `username` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  PRIMARY KEY (`model_id`) USING BTREE,
+  INDEX `algo_id`(`algo_id`) USING BTREE,
+  CONSTRAINT `model_ibfk_1` FOREIGN KEY (`algo_id`) REFERENCES `algorithm` (`algo_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 CREATE TABLE IF NOT EXISTS `workflow` (
-    `workflow_id`   CHAR(20) NOT NULL, 
-    `workflow_name` CHAR(10) NOT NULL, 
-    `status`        CHAR(12) NOT NULL, 
-    `description`   CHAR(50) NULL, 
-    `app_name`      CHAR(10) NOT NULL, 
-    `app_id`        CHAR(10) NOT NULL, 
-    `step`          INT(11)  NOT NULL, 
-    `period`        INT(11)  NOT NULL, 
-    `domain`        CHAR(20) NOT NULL, 
-    `username`      CHAR(40) NOT NULL, 
-    PRIMARY KEY (`workflow_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC ;
+  `workflow_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `workflow_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `description` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `create_time` int NOT NULL,
+  `status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `app_name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `app_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `step` int NULL DEFAULT NULL,
+  `period` int NULL DEFAULT NULL,
+  `domain` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  `username` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
+  PRIMARY KEY (`workflow_id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 
 CREATE TABLE IF NOT EXISTS `workflow_host` (
-    `host_id`     CHAR(32) NOT NULL, 
-    `workflow_id` CHAR(10) NULL, 
-    `host_name`   CHAR(20) NULL, 
-    `host_ip`     CHAR(16) NULL, 
-    PRIMARY KEY (`host_id`), 
-    KEY `workflow_id_auto_index` (`workflow_id`),
-    CONSTRAINT `FK_workflow_workflow_id` FOREIGN KEY (`workflow_id`) REFERENCES `workflow` (`workflow_id`) ON DELETE RESTRICT ON UPDATE RESTRICT
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC ;
+  `host_id` int NOT NULL,
+  `host_name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `host_ip` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  `workflow_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
+  PRIMARY KEY (`host_id`, `workflow_id`) USING BTREE,
+  INDEX `workflow_id`(`workflow_id`) USING BTREE,
+  CONSTRAINT `workflow_host_ibfk_1` FOREIGN KEY (`workflow_id`) REFERENCES `workflow` (`workflow_id`) ON DELETE CASCADE ON UPDATE RESTRICT
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
diff --git a/diana/database/dao/app_dao.py b/diana/database/dao/app_dao.py
index 653eb17..e5bce31 100644
--- a/diana/database/dao/app_dao.py
+++ b/diana/database/dao/app_dao.py
@@ -96,12 +96,12 @@ class AppDao(ElasticsearchProxy):
             return SUCCEED, result
 
         total_count = count_res[1]
-        paginate = dict(page=data["page"], size=data["per_page"])
+        paginate = dict(page=int(data["page"]), size=int(data["per_page"]))
         self._make_es_paginate_body(paginate, query_body)
         res = self.query(index, query_body, ["app_id", "version", "app_name", "description"])
         if res[0]:
             LOGGER.debug("query app list succeed")
-            result["total_page"] = (total_count + data["per_page"] - 1) / data["per_page"]
+            result["total_page"] = (total_count + int(data["per_page"]) - 1) / int(data["per_page"])
             result["total_count"] = total_count
             for item in res[1]['hits']['hits']:
                 result["app_list"].append(item['_source'])
-- 
Gitee

