1. 配置
1.1. maven 依赖
1 2 3 4 5 6 7 8 9 10 11 12 13
| <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> </dependency>
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
|
1.2. Spring 配置
1 2 3 4
| spring: flyway: enabled: true baseline-on-migrate: true
|
其他还有
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| spring: flyway: baseline-description: baseline-on-migrate: baseline-version: check-location: clean-on-validation-error: enabled: encoding: ignore-failed-future-migration: init-sqls: locations: out-of-order: password: placeholder-prefix: placeholder-replacementplaceholders: placeholder-suffix: placeholders.[placeholder name]: schemas: sql-migration-prefix: sql-migration-separator: sql-migration-suffix: tableflyway: target: url: user: validate-on-migrate:
|
1.3. 脚本
脚本默认目录: db/migration
脚本名称: V{version}__{name}.sql
固定的以 V 开头, 中间以双下划线分割.
flyway 只会执行比执行历史记录表(默认 flyway_schema_history) 中版本更大的脚本.
如: V1.0__init.sql
2. base-line
当项目存在历史数据, 需要告诉 flyway 在某个版本之前的脚本不需要执行了
1 2 3
| baseline-description: baseline-on-migrate: baseline-version:
|