Skip to content
m-szalik edited this page Jan 31, 2016 · 4 revisions

Maven plugin (maven-dbpatch-plugin)

Two methods of configuration

There are two different methods how you can configure dbpatch plugin.

If you are going to use this software without maven choose the 2nd option.
Example how to use it without maven.

Option 1: With pom.xml only

  • Put all necessary configuration into your pom.xml file.
<plugin>
     <groupId>org.jsoftware.dbpatch</groupId>
     <artifactId>dbpatch-maven-plugin</artifactId>
     <version>4.0</version>
 <configuration>
     <conf>
          <!-- put all configuration properties from properties file here -->
          <driverClass>org.postgresql.Driver</driverClass>
          <jdbcUri>jdbc:postgresql://localhost/my_db</jdbcUri>
          <username>db_username</username>
          <password>db_password</password>
          <patchDirs>dbpatches/main,dbpatches/testing</patchDirs>
          <!-- other properties -->
     </conf>
 </configuration>
 <dependencies>
    <dependency> <!-- Jdbc driver required to make connection to your database -->
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>8.4-701.jdbc4</version>
    </dependency>
 </dependencies>
 </plugin>

Working example.

Option 2: With a properties file

  • Put basic configuration template into your pom.xml file.
<plugin>
     <groupId>org.jsoftware.dbpatch</groupId>
     <artifactId>maven-dbpatch-plugin</artifactId>
     <version>4.0</version>
 <configuration>
     <configFile>dbpatch.properties</configFile> <!-- path to configuration file by default classpath:dbpatch.properties -->
     <selectedConfiguration>mydbconf</selectedConfiguration> <!-- database configuration, see dbpatch.properties file -->
 </configuration>
 <dependencies>
    <dependency> <!-- Jdbc driver required to make connection to your database -->
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>8.4-701.jdbc4</version>
    </dependency>
 </dependencies>
 </plugin>
  • Create dbpatch.properties file. Described below.
    Working example.

Properties file

Syntax

Each line contains profileID, propertyName and propertyValue profileID.propertyName = propertyValue
Lines starting with # are comments.

Configuration example

# configuration for first profile (mydb) postgreSQL
mydb.driverClass=org.postgresql.Driver
mydb.jdbcUri=jdbc:postgresql://localhost/my_db1
mydb.username=db_username
mydb.password=db_secretpass
# directories to scan for database patches (coma separated)
mydb.patchDirs=dbpatches/main,dbpatches/testing
# directories to scan for rollback patches (coma separated)
mydb.rollbackDirs=rollbacks

# configuration for next profile (db2) Oracle
db2.driverClass=oracle.jdbc.driver.OracleDriver
db2.jdbcUri=jdbc:oracle:thin:@localhost:1521:testdb
db2.username=db_username
# Get password from system property or environment variable named "db_secretpass"
db2.password=${db_secretpass}
db2.patchDirs=dbpatches – coma separated directories with patches
db2.dialect=oracle

Dialect

There are some major differences between databases, some databases required different SQL syntax. Sybase and Oracle users have to add property dialect and specify database dialect sybase or oracle.

Roll back patches

If property rollbackDirs is omitted the value of patchDirs is used with file mask *.rollback. You can change mask for rollback files using configuration property rollbackSuffix.
Example: mydb.rollbackSuffix=*.undo

See also Naming convention for SQL scripts

System properties and environment variables

You can use system properties -DpropertyName=properyValue and environment variables in configuration file by using ${key}. Where ${key} is replaced proper value. Example below:

db2.myProp=myValue${systemProp}
db2.key=ABC${myProp}

If systemProp is set by -DsystemProp=SP the results would be resolved as follows: db2.key=ABCmyValueSP