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/
  • 相关阅读:
    科技爱好者周刊(第 175 期):知识广度 vs 知识深度
    科技爱好者周刊(第 173 期):网络收音机的设计
    Telegra.ph | 简洁的文章发布平台
    前端规范
    Vue入门笔记三(Vuex)
    Vue入门笔记二
    Vue入门笔记一
    多点商城小程序案例笔记一
    sublime text 笔记
    windows下安装SASS
  • 原文地址:https://www.cnblogs.com/guoapeng/p/4925232.html
Copyright © 2011-2022 走看看