فهرست منبع

add flyway and init db script

ziyi.liu 4 سال پیش
والد
کامیت
45004509d2

+ 43 - 0
init-db/pom.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>graphql-demo</artifactId>
+        <groupId>com.remy</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>init-db</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.flywaydb</groupId>
+                <artifactId>flyway-maven-plugin</artifactId>
+                <version>7.11.1</version>
+                <configuration>
+                    <url><![CDATA[jdbc:mysql://localhost:3306/graphql-demo?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&useSSL=false]]></url>
+                    <user>graphql</user>
+                    <password>graphql</password>
+                    <configFileEncoding>UTF-8</configFileEncoding>
+                    <driver>com.mysql.cj.jdbc.Driver</driver>
+                </configuration>
+                <dependencies>
+                    <dependency>
+                        <groupId>mysql</groupId>
+                        <artifactId>mysql-connector-java</artifactId>
+                        <version>8.0.22</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 6 - 35
graphql-demo.sql → init-db/src/main/resources/db/migration/V1__init-db.sql

@@ -1,18 +1,3 @@
--- --------------------------------------------------------
--- 主机:                           127.0.0.1
--- 服务器版本:                        5.7.28-log - MySQL Community Server (GPL)
--- 服务器操作系统:                      Win64
--- HeidiSQL 版本:                  11.2.0.6213
--- --------------------------------------------------------
-
-/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
-/*!40101 SET NAMES utf8 */;
-/*!50503 SET NAMES utf8mb4 */;
-/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
-/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
-/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
-
--- 导出  表 graphql-demo.t_goods 结构
 CREATE TABLE IF NOT EXISTS `t_goods` (
     `id` bigint(20) NOT NULL AUTO_INCREMENT,
     `create_time` datetime(6) DEFAULT NULL,
@@ -27,8 +12,7 @@ CREATE TABLE IF NOT EXISTS `t_goods` (
     PRIMARY KEY (`id`)
     ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
 
--- 正在导出表  graphql-demo.t_goods 的数据:~6 rows (大约)
-/*!40000 ALTER TABLE `t_goods` DISABLE KEYS */;
+
 INSERT INTO `t_goods` (`id`, `create_time`, `update_time`, `description`, `detail`, `img`, `item_count`, `name`, `price`, `serial_no`) VALUES
 (1, '2021-06-21 16:49:12.094000', '2021-06-21 16:49:12.094000', 'GU女装起居套装(短袖)', 'GU女装起居套装(短袖)', 'https://graphql.cn/img/logo.svg', 99, 'GU女装', 74.00, 'pYmhjY58'),
 (2, '2021-06-21 16:52:30.200000', '2021-06-21 16:52:30.200000', '九阳电热饭盒可插电加热蒸煮便携', '九阳电热饭盒可插电加热蒸煮便携', 'https://graphql.cn/img/logo.svg', 125, '九阳电热饭盒', 159.00, '3qlihuWg'),
@@ -37,9 +21,8 @@ INSERT INTO `t_goods` (`id`, `create_time`, `update_time`, `description`, `detai
 (5, '2021-06-21 18:48:31.944000', '2021-06-21 18:48:31.944000', '现货德国WMF福滕宝实木盖研磨器2件装', 'Apple/苹果 iPhone 12', 'https://graphql.cn/img/logo.svg', 20, 'iPhone 12', 6299.00, 'INEnt8OV'),
 (6, '2021-06-21 18:52:05.178000', '2021-06-21 18:52:05.178000', '现货原版The Watercolorist\'s Essential Notebook水彩画家的必备笔记', '现货原版The Watercolorist\'s Essential Notebook水彩画家的必备笔记', 'https://graphql.cn/img/logo.svg', 66, 'Essential Notebook', 118.00, 'H5JJjJSj'),
 (7, '2021-06-21 18:53:48.153000', '2021-06-21 18:53:48.153000', 'LEGO乐高机械族42125 法拉利488GTE赛车拼搭积木男孩女孩收藏', 'LEGO乐高机械族42125 法拉利488GTE赛车拼搭积木男孩女孩收藏', 'https://graphql.cn/img/logo.svg', 66, '乐高法拉利488', 1869.00, '1K7gdmNM');
-/*!40000 ALTER TABLE `t_goods` ENABLE KEYS */;
 
--- 导出  表 graphql-demo.t_order 结构
+
 CREATE TABLE IF NOT EXISTS `t_order` (
     `id` bigint(20) NOT NULL AUTO_INCREMENT,
     `create_time` datetime(6) DEFAULT NULL,
@@ -53,8 +36,7 @@ CREATE TABLE IF NOT EXISTS `t_order` (
     PRIMARY KEY (`id`)
     ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8mb4;
 
--- 正在导出表  graphql-demo.t_order 的数据:~12 rows (大约)
-/*!40000 ALTER TABLE `t_order` DISABLE KEYS */;
+
 INSERT INTO `t_order` (`id`, `create_time`, `update_time`, `discount`, `discount_amount`, `goods_serial_no`, `order_no`, `original_amount`, `userid`) VALUES
 (13, '2021-06-22 10:23:06.601000', '2021-06-22 10:23:06.601000', 0.90, 66.60, 'pYmhjY58', '4bvd9i9pte', 74.00, 3),
 (14, '2021-06-22 10:23:38.583000', '2021-06-22 10:23:38.583000', 0.90, 143.10, '3qlihuWg', 'jnZ5nnHiK1', 159.00, 3),
@@ -69,9 +51,8 @@ INSERT INTO `t_order` (`id`, `create_time`, `update_time`, `discount`, `discount
 (23, '2021-06-22 10:24:57.448000', '2021-06-22 10:24:57.448000', 0.80, 59.20, 'pYmhjY58', 'wo9irE1ykw', 74.00, 5),
 (24, '2021-06-22 10:25:02.539000', '2021-06-22 10:25:02.539000', 0.80, 94.40, 'H5JJjJSj', 'RWLr4PxacG', 118.00, 5),
 (25, '2021-06-22 10:25:15.570000', '2021-06-22 10:25:15.570000', 0.80, 719.20, '5gqeGUEO', 'GivJBRVA7f', 899.00, 5);
-/*!40000 ALTER TABLE `t_order` ENABLE KEYS */;
 
--- 导出  表 graphql-demo.t_user 结构
+
 CREATE TABLE IF NOT EXISTS `t_user` (
     `id` bigint(20) NOT NULL AUTO_INCREMENT,
     `create_time` datetime(6) DEFAULT NULL,
@@ -88,15 +69,13 @@ CREATE TABLE IF NOT EXISTS `t_user` (
     UNIQUE KEY `UK_jhib4legehrm4yscx9t3lirqi` (`username`)
     ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
 
--- 正在导出表  graphql-demo.t_user 的数据:~2 rows (大约)
-/*!40000 ALTER TABLE `t_user` DISABLE KEYS */;
+
 INSERT INTO `t_user` (`id`, `create_time`, `update_time`, `age`, `birthday`, `gender`, `img`, `level`, `nickname`, `password`, `username`) VALUES
 (3, '2021-06-18 10:26:10.914000', '2021-06-18 10:26:10.914000', 30, '1985-02-22', 'MALE', 'https://www.baidu.com', 1, '小明', '3A548574B23819E3AF577B795AB8A147', 'remylee'),
 (4, '2021-06-21 19:02:34.540000', '2021-06-21 19:02:34.540000', 22, '1999-12-21', 'MALE', 'https://graphql.cn/img/logo.svg', 2, '杰克', '4D81FF7831351A0AEB58CC1719429002', 'jack'),
 (5, '2021-06-21 19:03:18.924000', '2021-06-21 19:03:18.924000', 21, '2000-02-12', 'FEMALE', 'https://graphql.cn/img/logo.svg', 3, '柔丝', '08DF54DA47C5E343DA8ABD541FEF87F6', 'rose');
-/*!40000 ALTER TABLE `t_user` ENABLE KEYS */;
 
--- 导出  表 graphql-demo.user_addresses 结构
+
 CREATE TABLE IF NOT EXISTS `user_addresses` (
     `user_id` bigint(20) NOT NULL,
     `addresses` varchar(255) DEFAULT NULL,
@@ -104,15 +83,7 @@ CREATE TABLE IF NOT EXISTS `user_addresses` (
     CONSTRAINT `FKpws20r8ion9y4yrp5828uad38` FOREIGN KEY (`user_id`) REFERENCES `t_user` (`id`)
     ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
--- 正在导出表  graphql-demo.user_addresses 的数据:~2 rows (大约)
-/*!40000 ALTER TABLE `user_addresses` DISABLE KEYS */;
 INSERT INTO `user_addresses` (`user_id`, `addresses`) VALUES
 (3, '上海'),
 (3, '北京'),
 (3, '重庆');
-/*!40000 ALTER TABLE `user_addresses` ENABLE KEYS */;
-
-/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
-/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
-/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
-/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;

+ 12 - 0
init-db/src/main/resources/db/migration/V2__add-comment.sql

@@ -0,0 +1,12 @@
+CREATE TABLE IF NOT EXISTS `t_comment`
+(
+    `id`              bigint(20) NOT NULL AUTO_INCREMENT,
+    `create_time`     datetime(6)  DEFAULT NULL,
+    `update_time`     datetime(6)  DEFAULT NULL,
+    `content`         varchar(255) DEFAULT NULL,
+    `goods_serial_no` varchar(255) DEFAULT NULL,
+    `order_no`        varchar(255) DEFAULT NULL,
+    `userid`          bigint(20)   DEFAULT NULL,
+    PRIMARY KEY (`id`)
+) ENGINE = InnoDB
+  DEFAULT CHARSET = utf8mb4;

+ 1 - 1
order-service/src/main/resources/application.yml

@@ -7,7 +7,7 @@ spring:
     username: graphql
     password: graphql
   jpa:
-#    generate-ddl: true
+    generate-ddl: true
     show-sql: true
 #    properties:
 #      hibernate:

+ 1 - 0
pom.xml

@@ -10,6 +10,7 @@
         <module>base-module</module>
         <module>graphql-api</module>
         <module>common-module</module>
+        <module>init-db</module>
     </modules>
     <groupId>com.remy</groupId>
     <artifactId>graphql-demo</artifactId>