From 730f7290797790cd60ab7dd1a4a1cd471c5144c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=A4=A9=E6=96=87?= <1002744113@qq.com> Date: Thu, 11 Aug 2022 22:12:03 +0800 Subject: [PATCH] =?UTF-8?q?refactor(sql):=20=E6=9B=B4=E6=96=B0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AEsql=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- document/sql/blink.sql | 2 +- document/sql/blog.sql | 27 +++++++-------------- document/sql/comment.sql | 2 +- document/sql/resource.sql | 16 +++++-------- document/sql/user.sql | 49 +++++++++++++++++---------------------- 5 files changed, 38 insertions(+), 58 deletions(-) diff --git a/document/sql/blink.sql b/document/sql/blink.sql index a2e58ff5..004ded9e 100644 --- a/document/sql/blink.sql +++ b/document/sql/blink.sql @@ -31,7 +31,7 @@ CREATE TABLE `blink` `modified_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 5 + AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Compact; diff --git a/document/sql/blog.sql b/document/sql/blog.sql index 034b8f41..473b69ea 100644 --- a/document/sql/blog.sql +++ b/document/sql/blog.sql @@ -1,10 +1,8 @@ /* Navicat Premium Data Transfer - Source Server : blog.sticki.live Source Server Type : MySQL Source Server Version : 50650 - Source Host : sql.blog.sticki.live:3306 Source Schema : blog Target Server Type : MySQL @@ -37,7 +35,7 @@ CREATE TABLE `blog` INDEX `author_id` (`author_id`) USING BTREE, INDEX `school_code` (`school_code`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 34 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = COMPACT; @@ -52,8 +50,7 @@ CREATE TABLE `blog_content` `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '博客内容', `modified_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', PRIMARY KEY (`blog_id`) USING BTREE, - UNIQUE INDEX `blog_id` (`blog_id`) USING BTREE, - CONSTRAINT `fk_blog_content_blog_1` FOREIGN KEY (`blog_id`) REFERENCES `blog` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT + UNIQUE INDEX `blog_id` (`blog_id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci @@ -88,8 +85,7 @@ CREATE TABLE `blog_general` `collection_num` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '收藏量', `score` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '评分', PRIMARY KEY (`blog_id`) USING BTREE, - UNIQUE INDEX `blog_id` (`blog_id`) USING BTREE, - CONSTRAINT `fk_blog_general_blog_1` FOREIGN KEY (`blog_id`) REFERENCES `blog` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT + UNIQUE INDEX `blog_id` (`blog_id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci @@ -105,10 +101,7 @@ CREATE TABLE `blog_set_tag` `tag_id` int(10) UNSIGNED NOT NULL, `blog_id` int(10) UNSIGNED NOT NULL, PRIMARY KEY (`id`) USING BTREE, - INDEX `fk_blog_set_tag_blog_1` (`blog_id`) USING BTREE, - INDEX `fk_blog_set_tag_tag_1` (`tag_id`) USING BTREE, - CONSTRAINT `fk_blog_set_tag_blog_1` FOREIGN KEY (`blog_id`) REFERENCES `blog` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT, - CONSTRAINT `fk_blog_set_tag_tag_1` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT + INDEX `index_tag_blog` (`tag_id`, `blog_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 @@ -127,10 +120,9 @@ CREATE TABLE `collect_blog` `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) USING BTREE, INDEX `fk_blog_collection_user_1` (`user_id`) USING BTREE, - INDEX `fk_blog_collection_blog_1` (`blog_id`) USING BTREE, - CONSTRAINT `collect_blog_ibfk_1` FOREIGN KEY (`blog_id`) REFERENCES `blog` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT + INDEX `fk_blog_collection_blog_1` (`blog_id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 8 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = COMPACT; @@ -159,7 +151,7 @@ CREATE TABLE `config` `result` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci NULL DEFAULT NULL COMMENT '值', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 2 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = Compact; @@ -176,10 +168,9 @@ CREATE TABLE `like_blog` `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', PRIMARY KEY (`id`) USING BTREE, INDEX `fk_blog_likes_user_1` (`user_id`) USING BTREE, - INDEX `fk_blog_likes_blog_1` (`blog_id`) USING BTREE, - CONSTRAINT `like_blog_ibfk_1` FOREIGN KEY (`blog_id`) REFERENCES `blog` (`id`) ON DELETE NO ACTION ON UPDATE RESTRICT + INDEX `fk_blog_likes_blog_1` (`blog_id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 35 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = COMPACT; diff --git a/document/sql/comment.sql b/document/sql/comment.sql index 2a11773e..e406b09e 100644 --- a/document/sql/comment.sql +++ b/document/sql/comment.sql @@ -32,7 +32,7 @@ CREATE TABLE `comment` `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 117 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = COMPACT; diff --git a/document/sql/resource.sql b/document/sql/resource.sql index 75df7eba..e576a60a 100644 --- a/document/sql/resource.sql +++ b/document/sql/resource.sql @@ -1,10 +1,8 @@ /* Navicat Premium Data Transfer - Source Server : blog.sticki.live Source Server Type : MySQL Source Server Version : 50650 - Source Host : sql.blog.sticki.live:3306 Source Schema : resource Target Server Type : MySQL @@ -27,10 +25,9 @@ CREATE TABLE `city` `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci NOT NULL COMMENT '名称', `province_id` int(10) UNSIGNED NOT NULL COMMENT '所属省份id', PRIMARY KEY (`id`) USING BTREE, - INDEX `province_id` (`province_id`) USING BTREE, - CONSTRAINT `city_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `province` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE + INDEX `province_id` (`province_id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 333 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = Compact; @@ -49,7 +46,7 @@ CREATE TABLE `image` PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `img` (`url`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 39 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = Compact; @@ -64,7 +61,7 @@ CREATE TABLE `province` `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci NOT NULL COMMENT '省份名称', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 35 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = Compact; @@ -86,10 +83,9 @@ CREATE TABLE `university` UNIQUE INDEX `code` (`code`) USING BTREE, UNIQUE INDEX `identifier` (`identifier`) USING BTREE, INDEX `name` (`name`) USING BTREE, - INDEX `city_id` (`city_id`) USING BTREE, - CONSTRAINT `university_ibfk_1` FOREIGN KEY (`city_id`) REFERENCES `city` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE + INDEX `city_id` (`city_id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 2629 + AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Compact; diff --git a/document/sql/user.sql b/document/sql/user.sql index aaadca1b..a8b95a67 100644 --- a/document/sql/user.sql +++ b/document/sql/user.sql @@ -1,10 +1,8 @@ /* Navicat Premium Data Transfer - Source Server : blog.sticki.live Source Server Type : MySQL Source Server Version : 50650 - Source Host : sql.blog.sticki.live:3306 Source Schema : user Target Server Type : MySQL @@ -29,7 +27,7 @@ CREATE TABLE `config` PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `param` (`param`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 2 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = Compact; @@ -49,7 +47,7 @@ CREATE TABLE `user` PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `username` (`username`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 46 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = COMPACT; @@ -70,8 +68,7 @@ CREATE TABLE `user_basic` `modified_time` datetime(6) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '信息修改时间', `name_modify_time` datetime(6) NULL DEFAULT NULL COMMENT '用户名修改时间', `start_work_time` datetime(6) NULL DEFAULT NULL COMMENT '开始工作的时间', - PRIMARY KEY (`username`) USING BTREE, - CONSTRAINT `user_basic_ibfk_1` FOREIGN KEY (`username`) REFERENCES `user` (`username`) ON DELETE CASCADE ON UPDATE RESTRICT + PRIMARY KEY (`username`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci @@ -115,11 +112,9 @@ CREATE TABLE `user_follow` `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', PRIMARY KEY (`id`) USING BTREE, INDEX `user_id` (`fans_id`) USING BTREE, - INDEX `follow_id` (`follow_id`) USING BTREE, - CONSTRAINT `user_follow_ibfk_1` FOREIGN KEY (`fans_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `user_follow_ibfk_2` FOREIGN KEY (`follow_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + INDEX `follow_id` (`follow_id`) USING BTREE ) ENGINE = InnoDB - AUTO_INCREMENT = 63 + AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = COMPACT; @@ -138,14 +133,27 @@ CREATE TABLE `user_safety` PRIMARY KEY (`user_id`) USING BTREE, UNIQUE INDEX `email` (`mail`) USING BTREE, UNIQUE INDEX `mobile` (`mobile`) USING BTREE, - INDEX `fk_user_safety_user_general_1` (`username`) USING BTREE, - CONSTRAINT `user_safety_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `user_safety_ibfk_2` FOREIGN KEY (`username`) REFERENCES `user` (`username`) ON DELETE CASCADE ON UPDATE CASCADE + INDEX `fk_user_safety_user_general_1` (`username`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_mysql500_ci ROW_FORMAT = COMPACT; +-- ---------------------------- +-- View structure for user_view +-- ---------------------------- +DROP VIEW IF EXISTS `user_view`; +CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `user_view` AS +select `user`.`id` AS `id`, + `user`.`username` AS `username`, + `user`.`nickname` AS `nickname`, + `user`.`school_code` AS `school_code`, + concat(`config`.`result`, `user`.`avatar_url`) AS `avatar_url`, + `user`.`register_time` AS `register_time` +from (`user` + join `config`) +where (`config`.`param` = 'avatar_url'); + -- ---------------------------- -- View structure for fans_view -- ---------------------------- @@ -184,19 +192,4 @@ select `user_follow`.`id` AS `id`, from (`user_follow` left join `user_view` on ((`user_view`.`id` = `user_follow`.`follow_id`))); --- ---------------------------- --- View structure for user_view --- ---------------------------- -DROP VIEW IF EXISTS `user_view`; -CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `user_view` AS -select `user`.`id` AS `id`, - `user`.`username` AS `username`, - `user`.`nickname` AS `nickname`, - `user`.`school_code` AS `school_code`, - concat(`config`.`result`, `user`.`avatar_url`) AS `avatar_url`, - `user`.`register_time` AS `register_time` -from (`user` - join `config`) -where (`config`.`param` = 'avatar_url'); - SET FOREIGN_KEY_CHECKS = 1;