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/
  • 相关阅读:
    Linux文件属性
    [Oracle] Listener的动态注册
    jQuery easyUI Pagination控件自定义div分页(不用datagrid)
    桂林电子科技大学出校流量控制器Android版1.0.0
    php使用check box
    Python windows ping
    Python selenium chrome 环境配置
    Linux wget auto login and backup database
    PyQt4 ShowHMDB show sqlite3 with QTableWidget summary
    PyQt4 py2exe 打包 HardwareManager
  • 原文地址:https://www.cnblogs.com/guoapeng/p/4925232.html
Copyright © 2011-2022 走看看