zoukankan      html  css  js  c++  java
  • 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

    转载请注明出处, 更多博文请访问https://www.cnblogs.com/guoapeng/
  • 相关阅读:
    HDU 5528 Count a * b 欧拉函数
    HDU 5534 Partial Tree 完全背包
    HDU 5536 Chip Factory Trie
    HDU 5510 Bazinga KMP
    HDU 4821 String 字符串哈希
    HDU 4814 Golden Radio Base 模拟
    LA 6538 Dinner Coming Soon DP
    HDU 4781 Assignment For Princess 构造
    LA 7056 Colorful Toy Polya定理
    LA 6540 Fibonacci Tree
  • 原文地址:https://www.cnblogs.com/guoapeng/p/4925232.html
Copyright © 2011-2022 走看看