
com.celum.dbtool.mojo.MigrateMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of db-maven-plugin Show documentation
Show all versions of db-maven-plugin Show documentation
DB plugin for Maven that executes SQL scripts
package com.celum.dbtool.mojo;
import com.celum.dbtool.Db;
import com.celum.dbtool.resource.DbStepResource;
import com.celum.dbtool.resource.DirResource;
import com.celum.dbtool.resource.PackageResource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.File;
/**
* @author Zdenko Vrabel ([email protected])
*
* @goal migrate
*/
public class MigrateMojo extends AbstractDbMojo
{
/**
* @parameter default-value="${basedir}/src/main/sql"
*/
protected File migrationScripts;
/**
* @parameter
*/
protected String migrationPackage;
/**
* @parameter default-value="PATCH"
*/
protected String patchTable;
/**
* @parameter default-value="true"
*/
protected boolean selfInitEnabled;
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
try {
registerVersionFactoryFromSettings();
Db.withJdbcConnection(getConnection(appAccount))
.createDefaultMigrationConfiguration(this.patchTable)
.withSelfInitIf(this.selfInitEnabled)
.andDbSteps(getResource())
.patch();
} catch (Exception e) {
getLog().error(e);
}
}
private DbStepResource getResource()
{
if (migrationPackage != null && !migrationPackage.isEmpty()) {
return new PackageResource(migrationPackage, getClassLoaderWithCompiledClasses());
} else {
return new DirResource(migrationScripts);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy