mvn_flyway-maven-plugin数据迁移插件

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&amp;characterEncoding=UTF-8&amp;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时 插件会自动执行 上述脚本文件

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值