Implement flyway in the form of code migration

If a project is dependent on another item in the form of jar package, flyway this project to achieve the following

 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                 // allowed before running version (with respect to the table schema latest version) of the schema file 
46 is                 .outOfOrder ( to true )
 47                 .load ()
 48                 .migrate ();
 49          
50          
51 is      }
 52 is  
53 is }

 

Guess you like

Origin www.cnblogs.com/guoAIrong/p/11417687.html