鹏叔(https://pengtech.net)

导航

LiquiBase 学习

 preconditions

 mysql database is installed

 maven has been setted up properly

 

add depedenceies

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'maven'

sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0.0'


  repositories {
     mavenLocal()

      mavenCentral()
  }

  

  dependencies {
      testCompile group: "junit", name: "junit", version: "$junitVersion"
      compile group: "log4j", name: "log4j", version: "1.2.17"
      compile group: "org.slf4j", name: "slf4j-log4j12", version: "1.7.5"

      compile group: "mysql", name: "mysql-connector-java", version: "5.1.31"

      compile group: "org.liquibase", name: "liquibase-core", version: "3.3.5"

  }

 

 

update database by liquibase API

public class Main {

    public static void main(String[] args) throws CommandLineParsingException, IOException {
        List<String> defaultArgs = Arrays.asList(
                "--logLevel=debug",
                "--driver=org.gjt.mm.mysql.Driver",
                "--url=jdbc:mysql://localhost/mysql",
                "--username=root",
                "--password=root",
                "--changeLogFile=update_database.xml",
                "update"
                );
        List<String> suppliedArgs = Arrays.asList(args);
        List<String> liquibaseArgs = new ArrayList<String>();
        liquibaseArgs.addAll(defaultArgs);
        liquibaseArgs.addAll(suppliedArgs);
        
        liquibase.integration.commandline.Main.main(liquibaseArgs.toArray(new String[liquibaseArgs.size()]));
    }

}
update_database.xml
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
    <includeAll path="update" />
</databaseChangeLog>

folder structure

C:\liquibase-example
---src
    +---main
    |   +---java
    |   |   \---com
    |   |       \---liquibase
    |   |           \---database
    |   \---resources
    |       \---update
    \---test
        +---java
        \---resources

  

 

 

reference documents:

http://ju.outofmemory.cn/entry/90761

http://www.tuicool.com/articles/Uvm2iaj

examples

http://blog.csdn.net/gadbee5/article/details/23461883

liquibase with gradle and spring

https://alphahinex.github.io/2018/05/15/liquibase-with-gradle

posted on 2015-10-31 11:36  eagle.supper  阅读(513)  评论(0编辑  收藏  举报