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/
  • 相关阅读:
    JSON学习笔记
    Java面试题之对static的理解
    【知了堂学习笔记】java基础知识之继承
    【知了堂学习笔记】多态基本知识
    Final关键字
    子父类构造函数特点
    原来学编程这么简单,如何理解程序的本质(今天听了【遇见狂神说】发布的《从HelloWorld到程序本质的思考》这个视频,有了自己的一些感悟,在这里和大家做一个分享)
    浅谈c3p0连接池和dbutils工具类的使用
    Mysql数据库重要知识点
    Express安装与调试
  • 原文地址:https://www.cnblogs.com/guoapeng/p/4925232.html
Copyright © 2011-2022 走看看