提交 3923b7e5 authored 作者: 周联昌's avatar 周联昌

ils-service:将数据库变更引入 flyway

ils-spring-example:补充readme.md说明
上级 1a48a1c7
流水线 #304 已失败 于阶段
...@@ -20,6 +20,5 @@ ...@@ -20,6 +20,5 @@
* model 已经 VO 里的类, 只要是会被作为返回值, 就需要用 swagger 的注释来解释. * model 已经 VO 里的类, 只要是会被作为返回值, 就需要用 swagger 的注释来解释.
## 数据库脚本 ## 数据库脚本
* 数据库脚本都在 resource 的 db_migration 中, 只要一个微服务有自己独立的数据库. * 数据库脚本都在 resource 的 db.migration 中, 只要一个微服务有自己独立的数据库.
* 其中 bootstrap 里包括完成的表单定义 * 其中 migration 里按照更新版本号来放 release 中数据库的更改脚本. 每个脚本的名字格式为 V`版本号`__`描述内容`.sql.
* 其中 migration 里按照月份来放该月 release 中数据库的更改脚本. 每个脚本的名字格式为 001.sql, 002.sql, 类推.
...@@ -82,6 +82,11 @@ ...@@ -82,6 +82,11 @@
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.58</version> <version>1.2.58</version>
</dependency> </dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.2.4</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -36,7 +36,7 @@ spring: ...@@ -36,7 +36,7 @@ spring:
name: ilsexample name: ilsexample
url: jdbc:mysql://localhost:3306/ilsexample?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8 url: jdbc:mysql://localhost:3306/ilsexample?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8
username: root username: root
password: root1234 password: 123456
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
filters: stat filters: stat
maxActive: 20 maxActive: 20
...@@ -53,11 +53,29 @@ spring: ...@@ -53,11 +53,29 @@ spring:
poolPreparedStatements: true poolPreparedStatements: true
maxOpenPreparedStatements: 20 maxOpenPreparedStatements: 20
initialize: false initialize: false
flyway:
# sql脚本迁移扫描的路径 默认是db/migration
locations: classpath:/db/migration
# 分隔版本标志符 默认是__
sql-migration-separator: __
# 文件的后缀名 默认是.sql
sql-migration-suffixes: .sql
# 开发环境设置为true 生产环境设置为false
out-of-order: true
# 数据库生成的迁移历史表名称 默认是flyway_schema_history
table: flyway_schema_history
# 开启或者关闭flyway
enabled: true
# 需要强调一点,在生产环境上必须关闭flyway:clean指令,因为一旦误操作,所有数据将会被清空
clean-disabled: true
# 告诉系统具体的baseline版本号 包括这条版本号在内的之前所有sql脚本,都不会在迁移时执行
baseline-version: -1
# 对于已经存在的项目,数据库中存在数据,这个时候我们需要通过设置baseline告诉flyway,这个baseline以及之前所有sql脚本都不要执行了
baseline-on-migrate: true
jpa: jpa:
hibernate: hibernate:
show-sql: true show-sql: true
database-platform: org.hibernate.dialect.MySQLDialect database-platform: org.hibernate.dialect.MySQLDialect
application: application:
name: ils-example-service name: ils-example-service
......
-- -----------------------------------------------------
-- Table `ilsexample`.`device`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS ilsexample.`device` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL DEFAULT NULL COMMENT '设备名',
`brand` VARCHAR(45) NULL DEFAULT NULL COMMENT '品牌',
`model` VARCHAR(45) NULL DEFAULT NULL COMMENT '模型',
`enabled` TINYINT(4) NULL DEFAULT NULL COMMENT '激活',
`weight` DOUBLE NULL DEFAULT NULL COMMENT '重量\n',
`length` INT(11) NULL DEFAULT NULL COMMENT '长度 cm',
`height` INT(11) NULL DEFAULT NULL COMMENT '高度 cm',
PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
-- Table `ilsexample`.`measurement`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS ilsexample.`measurement` (
`id` INT(11) NOT NULL,
`name` VARCHAR(45) NULL DEFAULT NULL COMMENT '监控参数标准名-英文',
`unit` VARCHAR(45) NULL DEFAULT NULL COMMENT '单位',
`alias` VARCHAR(45) NULL DEFAULT NULL COMMENT '其他名字',
PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;
\ No newline at end of file
-- 该文件为不使用flyway之前的sql文件,仅作为一份留存文件,无实际意义。
-- MySQL Workbench Forward Engineering -- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论