From f04fc2680e395a336b05bac85bb5b4f4ad52113d Mon Sep 17 00:00:00 2001
From: jiangyitao <451988022@163.com>
Date: Wed, 29 Jul 2020 11:49:59 +0800
Subject: [PATCH] add flyway
---
db/data.sql | 22 -------
db/database.sql | 3 -
db/update.sql | 57 -------------------
pom.xml | 6 +-
src/main/resources/application.properties | 9 ++-
.../resources/db/migration/V0.7.5__init.sql | 23 ++++++++
6 files changed, 36 insertions(+), 84 deletions(-)
delete mode 100644 db/data.sql
delete mode 100644 db/database.sql
delete mode 100644 db/update.sql
rename db/table.sql => src/main/resources/db/migration/V0.7.5__init.sql (90%)
diff --git a/db/data.sql b/db/data.sql
deleted file mode 100644
index 6386cff..0000000
--- a/db/data.sql
+++ /dev/null
@@ -1,22 +0,0 @@
--- 账号admin 密码admin
-INSERT INTO `user`(`id`,`username`, `password`, `nick_name`, `status`, `create_time`) VALUES ('1', 'admin', '$2a$12$v1ERBqyxhU/ocHRPywOjvOAMkhmZGJB3hRoNjr4bWO3HLWZSIlnne', '超级管理员', 1, '2020-02-24 20:14:33');
-INSERT INTO `user_role`(`user_id`, `role_id`) VALUES (1, 1);
-INSERT INTO `project`(`id`, `name`, `description`, `platform`, `creator_uid`, `create_time`) VALUES (1, 'AndroidDemo', '', 1, 1, '2020-02-24 20:14:33');
-INSERT INTO `user_project`(`user_id`, `project_id`) VALUES (1, 1);
-
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (1, 'admin', '超级管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (2, 'browser', '浏览器管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (3, 'app', 'app管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (4, 'mobile', 'mobile管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (5, 'driver', 'driver管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (6, 'environment', '环境管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (7, 'globalVar', '全局变量管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (8, 'page', 'page管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (9, 'action', 'action管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (10, 'testcase', '测试用例管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (11, 'testPlan', '测试计划管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (12, 'testTask', '测试任务管理员');
-INSERT INTO `role`(`id`, `name`, `alias`) VALUES (13, 'testSuite', '测试集管理员');
-
-INSERT INTO `category`(`id`, `name`, `type`, `create_time`, `creator_uid`) VALUES (10000, '废弃', 5, '2020-07-23 18:21:00', 1);
-
diff --git a/db/database.sql b/db/database.sql
deleted file mode 100644
index e3108d1..0000000
--- a/db/database.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-DROP DATABASE if exists `daxiang`;
-CREATE DATABASE `daxiang` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';
-use `daxiang`;
\ No newline at end of file
diff --git a/db/update.sql b/db/update.sql
deleted file mode 100644
index b7792e5..0000000
--- a/db/update.sql
+++ /dev/null
@@ -1,57 +0,0 @@
--- 0.5.5
-ALTER TABLE `page`
-MODIFY COLUMN `window_orientation` varchar(11) NULL COMMENT '屏幕方向' AFTER `window_width`;
-
-ALTER TABLE `page`
-ADD COLUMN `type` tinyint(4) NOT NULL COMMENT '1.android_native 2.ios_native 3.web' AFTER `project_id`;
-
-UPDATE page pg JOIN project pj ON pg.project_id = pj.id SET type = IF(pj.platform = 1, 1, 2)
-
--- 0.5.8
-CREATE TABLE `browser` (
- `id` varchar(100) NOT NULL COMMENT '浏览器id',
- `type` varchar(50) NOT NULL COMMENT '类型: chrome firefox ...',
- `version` varchar(50) NOT NULL COMMENT '版本号',
- `platform` tinyint(4) NOT NULL COMMENT '平台: 1. windows 2.linux 3.macos',
- `status` tinyint(4) DEFAULT NULL COMMENT '状态:0.离线 1.使用中 2.空闲',
- `agent_ip` varchar(50) DEFAULT NULL COMMENT '浏览器所在的agent的ip',
- `agent_port` int(11) DEFAULT NULL COMMENT '浏览器所在的agent的端口',
- `last_online_time` datetime DEFAULT NULL COMMENT '最近一次在线时间',
- `username` varchar(100) DEFAULT NULL COMMENT '最近一次使用人',
- `create_time` datetime DEFAULT NULL COMMENT '创建时间',
- PRIMARY KEY (`id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='浏览器表';
-
-ALTER TABLE `project`
-MODIFY COLUMN `platform` tinyint(4) NOT NULL COMMENT '1.andorid 2.iOS 3.pc web' AFTER `description`,
-ADD COLUMN `capabilities` text NULL COMMENT 'org.openqa.selenium.Capabilities' AFTER `platform`;
-
-ALTER TABLE `device_test_task`
-ADD COLUMN `capabilities` text NULL COMMENT 'org.openqa.selenium.Capabilities' AFTER `platform`;
-
-ALTER TABLE `device` DROP COLUMN `last_offline_time`;
-
-delete from `action` where id < 10000 -- 重新导入基础action https://github.com/opendx/agent/tree/master/src/main/java/com/daxiang/action/action.sql
-
--- 0.6.5
-RENAME TABLE `device` TO `mobile`;
-ALTER TABLE `mobile` ADD COLUMN `emulator` tinyint(4) NULL COMMENT '0: 真机 1: 模拟器' AFTER `name`;
-
-update role set name='browser',alias='浏览器管理员' where id = 2;
-update role set name='mobile',alias='mobile管理员' where id = 4;
-
-ALTER TABLE `device_test_task`
-ADD COLUMN `device` json NULL COMMENT '下发任务时的device' AFTER `device_id`;
-
--- 0.7.0
-ALTER TABLE `category`
-ADD COLUMN `parent_id` int(11) NOT NULL DEFAULT 0 COMMENT '父id' AFTER `id`;
-
-ALTER TABLE `category`
-MODIFY COLUMN `project_id` int(11) NULL COMMENT '所属项目的id' AFTER `type`;
-
--- 0.7.5
-ALTER TABLE `action`
-CHANGE COLUMN `return_value` `return_value_type` varchar(255) NOT NULL COMMENT '返回值类型: void / 其他' AFTER `invoke`;
-
-INSERT INTO `category`(`id`, `name`, `type`, `create_time`, `creator_uid`) VALUES (10000, '废弃', 5, '2020-07-23 17:11:00', 1);
diff --git a/pom.xml b/pom.xml
index 125dda9..3fa410f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,7 +86,11 @@
guava
25.0-jre
-
+
+ org.flywaydb
+ flyway-core
+ 5.2.4
+
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index bf35c62..dcbaac1 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -20,4 +20,11 @@ static-location=static
frontend=frontend
spring.resources.static-locations=file:${static-location}
-version=@project.version@
\ No newline at end of file
+#pom项目版本
+version=@project.version@
+
+#flyway配置
+spring.flyway.baseline-on-migrate=true
+spring.flyway.baseline-version=0.7.5
+
+
diff --git a/db/table.sql b/src/main/resources/db/migration/V0.7.5__init.sql
similarity index 90%
rename from db/table.sql
rename to src/main/resources/db/migration/V0.7.5__init.sql
index ab9483b..7ce4aff 100644
--- a/db/table.sql
+++ b/src/main/resources/db/migration/V0.7.5__init.sql
@@ -353,3 +353,26 @@ CREATE TABLE `environment` (
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_name_projectId` (`name`,`project_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='环境表';
+
+
+-- 账号admin 密码admin
+INSERT INTO `user`(`id`,`username`, `password`, `nick_name`, `status`, `create_time`) VALUES ('1', 'admin', '$2a$12$v1ERBqyxhU/ocHRPywOjvOAMkhmZGJB3hRoNjr4bWO3HLWZSIlnne', '超级管理员', 1, '2020-02-24 20:14:33');
+INSERT INTO `user_role`(`user_id`, `role_id`) VALUES (1, 1);
+INSERT INTO `project`(`id`, `name`, `description`, `platform`, `creator_uid`, `create_time`) VALUES (1, 'AndroidDemo', '', 1, 1, '2020-02-24 20:14:33');
+INSERT INTO `user_project`(`user_id`, `project_id`) VALUES (1, 1);
+
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (1, 'admin', '超级管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (2, 'browser', '浏览器管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (3, 'app', 'app管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (4, 'mobile', 'mobile管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (5, 'driver', 'driver管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (6, 'environment', '环境管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (7, 'globalVar', '全局变量管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (8, 'page', 'page管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (9, 'action', 'action管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (10, 'testcase', '测试用例管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (11, 'testPlan', '测试计划管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (12, 'testTask', '测试任务管理员');
+INSERT INTO `role`(`id`, `name`, `alias`) VALUES (13, 'testSuite', '测试集管理员');
+
+INSERT INTO `category`(`id`, `name`, `type`, `create_time`, `creator_uid`) VALUES (10000, '废弃', 5, '2020-07-23 18:21:00', 1);