liquibase using maven with two databases does not work

前端 未结 1 1206
不思量自难忘°
不思量自难忘° 2020-12-11 05:44

This post describes how to update two databases from maven using liquibase: liquibase using maven with two databases However, when I try the exact same configuration in my p

1条回答
  •  一整个雨季
    2020-12-11 06:18

    Does your build need to update 2 databases in one go? An alternative approach is to use Maven profiles as follows:

    mvn process-resources
    mvn -Pdb2 process-resources
    

    Project files

    |-- pom.xml
    `-- src
        `-- main
            `-- resources
                |-- com
                |   `-- myspotontheweb
                |       `-- db
                |           `-- changelog
                |               |-- db-changelog-1.0.xml
                |               `-- db-changelog-master.xml
                `-- liquibase.properties
    

    I prefer to use Maven's generate-resources phase to create a liquibase properties file.

    pom.xml

    Contains two profiles at the end containing the properties associated with the two databases. This solution scales to any number of db environments.

    Another item of note is that liquibase uses the populated properties under the targets directory

    
        4.0.0
        com.myspotontheweb.db
        liquibase-demo
        1.0-SNAPSHOT
        
            
                com.h2database
                h2
                1.3.162
            
        
        
            
                
                    src/main/resources
                    true
                
            
            
                
                    org.liquibase
                    liquibase-maven-plugin
                    2.0.1
                    
                        
                            process-resources
                            
                                target/classes/liquibase.properties
                                false
                            
                            
                                update
                            
                        
                    
                
            
        
        
            
                db1
                
                    true
                
                
                    jdbc:h2:target/db1/liquibaseTest;AUTO_SERVER=TRUE
                    org.h2.Driver
                    user
                    pass
                
            
            
                db2
                
                    jdbc:h2:target/db2/liquibaseTest;AUTO_SERVER=TRUE
                    org.h2.Driver
                    user
                    pass
                
            
        
    
    

    liquibase.properties

    This is the template file populated with the profile property values for the specific environment.

    # Database credentials
    url=${liquibase.url}
    driver=${liquibase.driver}
    username=${liquibase.username}
    password=${liquibase.password}
    
    # Liquibase changelog
    changeLogFile=com/myspotontheweb/db/changelog/db-changelog-master.xml
    

    Update

    And alternative strategy would be to run the plug-in directly, instead of integrating it into a Maven life-cycle.

    mkdir target
    mvn liquibase:update
    mvn -Pdb2 liquibase:update
    

    Again you are using a profile to control the property settings.

    pom.xml

    The difference is that the plug-ins settings are controlled by properties set in the profile. No more properties file created under the targets directory for shipment in your jar.

    
        4.0.0
        com.myspotontheweb.db
        liquibase-demo
        1.0-SNAPSHOT
        
            
                com.h2database
                h2
                1.3.162
            
        
        
            
                
                    org.liquibase
                    liquibase-maven-plugin
                    2.0.1
                    
                        ${liquibase.url}
                        ${liquibase.driver}
                        ${liquibase.username}
                        ${liquibase.password}
                        src/main/resources/com/myspotontheweb/db/changelog/db-changelog-master.xml
                        false
                    
                
            
        
        
            
                db1
                
                    true
                
                
                    jdbc:h2:target/db1/liquibaseTest;AUTO_SERVER=TRUE
                    org.h2.Driver
                    user
                    pass
                
            
            
                db2
                
                    jdbc:h2:target/db2/liquibaseTest;AUTO_SERVER=TRUE
                    org.h2.Driver
                    user
                    pass
                
            
        
    
    

    0 讨论(0)
提交回复
热议问题