Flyway 数据库版本管理
大约 2 分钟
Flyway 数据库版本管理
最后一个支持 MySQL5.7 的社区版本
- Q: Stackoverflow: What is the last version of flyway community edition that supported MySQL 5.7
- A:
7.15.0
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>flywaydb-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.31</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.flywaydb/flyway-core -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>7.15.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/flywaydb
spring.datasource.username=root
spring.datasource.password=*c_c>CLos7cf
src/main/resources/db/migration/V1_1__ddl.sql
create table tb_device(
device_id bigint not null auto_increment,
device_type int default null,
primary key (device_id)
);
src/main/resources/db/migration/V1_2__dml.sql
create table tb_device_0 like tb_device;
create table tb_device_1 like tb_device;
运行结果
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.5)
2022-12-04 21:30:45.457 INFO 17872 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
2022-12-04 21:30:46.112 INFO 17872 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-12-04 21:30:47.126 INFO 17872 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-12-04 21:30:47.160 INFO 17872 --- [ main] o.f.c.internal.license.VersionPrinter : Flyway Community Edition 7.15.0 by Redgate
2022-12-04 21:30:47.161 INFO 17872 --- [ main] o.f.c.i.database.base.BaseDatabaseType : Database: jdbc:mysql://localhost:3306/flywaydb (MySQL 5.7)
2022-12-04 21:30:47.196 INFO 17872 --- [ main] o.f.core.internal.command.DbValidate : Successfully validated 2 migrations (execution time 00:00.016s)
2022-12-04 21:30:47.204 INFO 17872 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema `flywaydb`: << Empty Schema >>
2022-12-04 21:30:47.212 INFO 17872 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema `flywaydb` to version "1.1 - ddl"
2022-12-04 21:30:47.244 INFO 17872 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema `flywaydb` to version "1.2 - dml"
2022-12-04 21:30:47.283 INFO 17872 --- [ main] o.f.core.internal.command.DbMigrate : Successfully applied 2 migrations to schema `flywaydb`, now at version v1.2 (execution time 00:00.082s)
2022-12-04 21:30:47.365 INFO 17872 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 2.191 seconds (JVM running for 2.517)
2022-12-04 21:30:47.370 INFO 17872 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-12-04 21:30:47.382 INFO 17872 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 0
(全文完)