Introduction
In this chapter some examples will show how to use the Migration Plugin goals:
Generic Plugin configuration information
Before starting, please take a look at the following links to know more how to include and configure Maven plugins in the POM project:
pom.xml Plugin configuration
To use Migration Maven plugin in your project you have to configure your pom.xml
file like this:
<plugins>
<plugin>
<groupId>org.mybatis.maven</groupId>
<artifactId>migrations-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<repository> [migration repository path] </repository>
</configuration>
<dependencies>
[ add your jdbc driver depencency ]
</dependencies>
</plugin>
<plugins>
The migration:status goal
This goal prints the current migration status of database. A tipical output could be:
mvn migration:status -Dmigration.path=/path/to/migration/repository ... [INFO] Executing Apache Migration StatusCommand [INFO] ID Applied At Description [INFO] ================================================================================ [INFO] 20100400000001 ...pending... create changelog [INFO] 20100400000002 ...pending... first migration [INFO] 20100400000003 ...pending... second migration [INFO] ...
The migration:check goal
checks the current status of your database migration and fails if one or more script are pending. A typical use of this goal is check the migration status into your maven build life cycle:
<plugin>
<groupId>org.mybatis.maven</groupId>
<artifactId>migrations-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<repository> [migration repository path] </repository>
</configuration>
<executions>
<execution>
<id>migration-chack</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency> [your jdbc dependency] </dependency>
</dependencies>
</plugin>
and then
mvn clean test
this goal fails if migration plugin founds one or more pending script. To skip the
migration check set the properties migration.skip
like this:
mvn -Dmigration.skip=true clean test
Site report for Maven 2 projects
You can configure your pom.xml
to create a simple report of your database status:
<build>
...
<plugins>
<plugin>
<groupId>org.mybatis.maven</groupId>
<artifactId>migrations-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<repository> [migration repository path] </repository>
</configuration>
<executions>
<execution>
<id>migration-chack</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency> [your jdbc dependency] </dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.mybatis.maven</groupId>
<artifactId>migrations-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<repository> [migration repository path] </repository>
</configuration>
</plugin>
</plugins>
</reporting>
once the plugin is configured, users can invoke:
mvn site
Site report for Maven 3 projects
You can configure your pom.xml
to create a simple report of your database status:
<build>
...
<plugins>
<plugin>
<groupId>org.mybatis.maven</groupId>
<artifactId>migrations-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<repository> [migration repository path] </repository>
</configuration>
<executions>
<execution>
<id>migration-chack</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency> [your jdbc dependency] </dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.6</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.mybatis.maven</groupId>
<artifactId>migrations-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<repository> [migration repository path] </repository>
</configuration>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
...
once the plugin is configured, users can invoke:
mvn site