pom.xml
<build>
<plugins>
xxx具体的插件xxx
</plugins>
</build>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<executions>
<!--当install时会执行migrate-->
<execution>
<phase>generate-sources</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://xxipxx:xxportxx/xxdb.schemaxx?useUnicode=true&characterEncoding=UTF-8&useSSL=false</url>
<user>root</user>
<password>1234</password>
<!--<schemas></schemas>-->
</configuration>
</plugin>
在数据库中创建迁移记录表
这张表里面记录的已经运行过的脚本的hash,如果你改了脚本,把这张表清空一下再install
-- ----------------------------
-- Table structure for flyway_schema_history
-- ----------------------------
DROP TABLE IF EXISTS `flyway_schema_history`;
CREATE TABLE `flyway_schema_history` (
`installed_rank` int(11) NOT NULL,
`version` varchar(50) DEFAULT NULL,
`description` varchar(200) NOT NULL,
`type` varchar(20) NOT NULL,
`script` varchar(1000) NOT NULL,
`checksum` int(11) DEFAULT NULL,
`installed_by` varchar(100) NOT NULL,
`installed_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`execution_time` int(11) NOT NULL,
`success` tinyint(1) NOT NULL,
PRIMARY KEY (`installed_rank`),
KEY `flyway_schema_history_s_idx` (`success`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
项目中默认SQL脚本执行地方
/src/main/resources/db/migration/
V1__createTable.sql
V2__initData.sql
这样 每在在mvn install时 插件会自动执行 上述脚本文件