maven-deploy-plugin插件

dbdeploy 是一个工具,用来记录数据库开发留下修改历史。

利用Dbdeploy工具为我们带的好处
1、历史修改留痕,方便追溯或回滚某一时间数据库结构和数据
2、利用命令自动打包sql脚本
3、可利用历史记录快速复制干净的数据库,实现一人一库开发,数据隔离,不影响测试过程
4、防止开发人员在开发过程中随意在数据库上更改脚本

插件使用示例

maven配置

mysql示例


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <groupId>testgroupId>
    <artifactId>mysql-dbdeployartifactId>

    <properties>
        <db.host>127.0.0.1db.host>
        <db.url>jdbc:mysql://${db.host}:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghaidb.url>
        <db.usr>rootdb.usr>
        <db.pwd>123456db.pwd>
        <java.version>1.8java.version>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    properties>

    <build>
        <plugins>
            <plugin>
                <groupId>com.dbdeploygroupId>
                <artifactId>maven-dbdeploy-pluginartifactId>
                <version>3.0M3version>
                <configuration>
                    <scriptdirectory>./src/main/sqlscriptdirectory>
                    <name>${name}name>
                    <encoding>UTF-8encoding>
                    <lineEnding>lflineEnding>
                    <outputfile>./target/apply.sqloutputfile>
                    <undoOutputfile>./target/undo.sqlundoOutputfile>
                    <driver>com.mysql.cj.jdbc.Driverdriver>
                    <url>${db.url}url>
                    <userid>${db.usr}userid>
                    <password>${db.pwd}password>
                    <dbms>mysqldbms>
                    
                    <delimiter>;delimiter>
                    <delimiterType>rowdelimiterType>
                configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysqlgroupId>
                        <artifactId>mysql-connector-javaartifactId>
                        <version>8.0.21version>
                        <scope>runtimescope>
                    dependency>
                    <dependency>
                        <groupId>com.dbdeploygroupId>
                        <artifactId>dbdeploy-coreartifactId>
                        <version>3.0M3version>
                    dependency>
                dependencies>
            plugin> 
        plugins>
    build>

project>

Oracle示例


<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
         
    <groupId>testgroupId>
    <artifactId>oracleartifactId>

    <build>
        <plugins>
            <plugin>
                <groupId>com.dbdeploygroupId>
                <artifactId>maven-dbdeploy-pluginartifactId>
                <version>3.0M3version>
                <configuration>
                    <scriptdirectory>./src/main/sqlscriptdirectory>
                    <name>${dbchangefile.name}name>
                    <encoding>UTF-8encoding>
                    <lineEnding>lflineEnding>
                    <outputfile>./target/apply.sqloutputfile>
                    <undoOutputfile>./target/undo.sqlundoOutputfile>
                    <driver>oracle.jdbc.OracleDriverdriver>
                    <url>${db.url}url>
                    <userid>${db.usr}userid>
                    <password>${db.pwd}password>
                    <dbms>oradbms>
                    <delimiter>;delimiter>
                    <delimiterType>rowdelimiterType>
                configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.oraclegroupId>
                        <artifactId>ojdbc6artifactId>
                        <version>11.2.0.1.0version>
                    dependency>
                    <dependency>
                        <groupId>com.oraclegroupId>
                        <artifactId>orai18nartifactId>
                        <version>11.2.0.1.0version>
                    dependency>
                dependencies>
            plugin>
        plugins>
    build>

project>

创建记录表

create table changelog
(
    CHANGE_NUMBER NUMERIC(22)  not null,
    COMPLETE_DT   DATETIME     not null,
    APPLIED_BY    VARCHAR(100) not null,
    DESCRIPTION   VARCHAR(500) not null,
    primary key (CHANGE_NUMBER)
);

批处理命令

1.createNewDDLChangeFile.bat
该命令用于生成DDL语句

mvn dbdeploy:change-script -Dname=DDL

2.createNewDDLChangeFile.bat
该命令用于生成DML语句

mvn dbdeploy:change-script -Dname=DML

3.update.bat
该命令用于执行记录表里未记录的SQL文件

mvn dbdeploy:update -Ddb.host=127.0.0.1 -Dscriptdirectory=./src/main/sql > creditsql.log

项目目录结构

maven-deploy-plugin插件_第1张图片

你可能感兴趣的:(maven,数据库)