|
|
|
Database migration scripts break a deployment in no time, that is common knowledge. Changed by accident or through the IDE the verification at application startup stops it.
The MigrationChange-Checker(MCC) provides a possible solution for that issue. It will make tests fail early instead of breaking the deployment.
MCC is available via Maven Central.
To use it with gradle add following into the build.gradle:
repositories {
mavenCentral()
}
dependencies {
testCompile 'de.pixel.mcc:MigrationChange-Checker:<version>'
}
To use it in a maven project add this in the pom.xml:
<project>
...
<dependencies>
<dependency>
<groupId>de.pixel.mcc</groupId>
<artifactId>MigrationChange-Checker</artifactId>
<version><!--version--></version>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
MCC has a fluent way to interact. A basic usage is shown below:
MigrationChangeChecker.setup()
.withHashAlgorithm(HashAlgorithm.MD5)
.withHashPair("migration.sql", "thisIsMyPrecalculatedMd5Hash1234")
.verifyFile(Paths.get("path/to/migration.sql"));
With the optional .withHashAlgorithm(...)
the used hash mechanism can be set. MMC supports MD5
,SHA-256
and SHA-512
right now. If
none is set, SHA-256
is used.
The .withHashPair(<filename>, <hash>)
adds a new hash to the internal collection. To calculate the hash use a tool of your liking or
extract the hash from the log of a failed verification.
To verify a file use .verifyFile(<path>)
. It accepts a java.nio.file.Path
as parameter and try to match a stored checksum.
To use the checker, a parameterized test class is recommended. The example uses junit5
but other java compatible testing frameworks work
as well.
The example lives in the test packages: Example Test