zoukankan      html  css  js  c++  java
  • 以代码的形式实现flyway的迁移

    如果某个项目被另一个项目以jar包的形式依赖,此项目的flyway实现如下

     1 package com.enmo.dbaas.firewall.common.config;
     2 
     3 import org.flywaydb.core.Flyway;
     4 import org.flywaydb.core.api.configuration.FluentConfiguration;
     5 import org.springframework.stereotype.Component;
     6 import com.enmo.dbaas.firewall.common.utils.SpringContextProvider;
     7 import lombok.extern.slf4j.Slf4j;
     8 
     9 /**
    10  * @ClassName: FlywayConfig.java
    11  * @Description:
    12  * @Author guo.yu
    13  * @Version V1.0.0
    14  * @Date 2019-05-12 19:46:10
    15  */
    16 @Component
    17 @Slf4j
    18 public class FlywayConfig {
    19 
    20     private static final String FLYWAY_TAB_NAME = "dbaas_firewall_flyway_schema_history";
    21     
    22     private static final String FLYWAY_LOCATION = "db/firewall/migration";
    23 
    24     public FlywayConfig(SpringContextProvider provider) {
    25         Flyway defFlyway = null;
    26         try {
    27             defFlyway = provider.getBean(Flyway.class);
    28         } catch (Exception e) {
    29             log.warn("flyway is not enabled.");
    30         }
    31         if (defFlyway != null) {
    32             firewallMigrate(defFlyway);
    33         }
    34 
    35     }
    36 
    37     @SuppressWarnings("deprecation")
    38     public void firewallMigrate(Flyway defFlyway) {
    39         FluentConfiguration config = new FluentConfiguration();
    40 
    41         config.dataSource(defFlyway.getDataSource())
    42                .baselineOnMigrate(defFlyway.isBaselineOnMigrate())
    43                .locations(FLYWAY_LOCATION)
    44                .table(FLYWAY_TAB_NAME)
    45                //允许运行之前版本(相对于schema表最新版本)的schema文件
    46                .outOfOrder(true)
    47                .load()
    48                .migrate();
    49         
    50         
    51     }
    52 
    53 }
  • 相关阅读:
    E4A易安卓3.6无需注册编译Release
    PHP中几种常用的网页跳转代码
    超详细教你重新封装GHO(ndeer和绿茶)教程
    程序员和编码员之间的区别
    迅闪三层下载游戏无速度
    POST注册DZ论坛或发帖
    解决局域网文件共享设置
    妻子 情人 红颜知己
    照片与同行元素居中的方法
    【转】SVN使用教程总结
  • 原文地址:https://www.cnblogs.com/guoAIrong/p/11417687.html
Copyright © 2011-2022 走看看