use of liquibase.Liquibase in project dropwizard by dropwizard.
the class DbLocksCommandTest method testRelease.
@Test
void testRelease() throws Exception {
// We can't create locks in the database, so use mocks
final Liquibase liquibase = Mockito.mock(Liquibase.class);
locksCommand.run(new Namespace(Maps.of("list", false, "release", true)), liquibase);
Mockito.verify(liquibase).forceReleaseLocks();
}
use of liquibase.Liquibase in project liquibase by liquibase.
the class AbstractDatabaseDiffTask method getDiffResult.
protected DiffResult getDiffResult() {
Liquibase liquibase = getLiquibase();
Database targetDatabase = liquibase.getDatabase();
Database referenceDatabase = createDatabaseFromType(referenceDatabaseType, getResourceAccessor());
CatalogAndSchema targetCatalogAndSchema = buildCatalogAndSchema(targetDatabase);
CatalogAndSchema referenceCatalogAndSchema = buildCatalogAndSchema(referenceDatabase);
CompareControl.SchemaComparison[] schemaComparisons = { new CompareControl.SchemaComparison(referenceCatalogAndSchema, targetCatalogAndSchema) };
SnapshotGeneratorFactory snapshotGeneratorFactory = SnapshotGeneratorFactory.getInstance();
DatabaseSnapshot referenceSnapshot;
try {
referenceSnapshot = snapshotGeneratorFactory.createSnapshot(referenceDatabase.getDefaultSchema(), referenceDatabase, new SnapshotControl(referenceDatabase, diffTypes));
} catch (LiquibaseException e) {
throw new BuildException("Unable to create a DatabaseSnapshot: " + e.getMessage(), e);
}
CompareControl compareControl = new CompareControl(schemaComparisons, referenceSnapshot.getSnapshotControl().getTypesToInclude());
try {
return liquibase.diff(referenceDatabase, targetDatabase, compareControl);
} catch (LiquibaseException e) {
throw new BuildException("Unable to diff databases: " + e.getMessage(), e);
}
}
use of liquibase.Liquibase in project liquibase by liquibase.
the class BaseLiquibaseTask method execute.
@Override
public final void execute() throws BuildException {
super.execute();
log(coreBundle.getString("starting.liquibase"), Project.MSG_INFO);
classLoader = getProject().createClassLoader(classpath);
classLoader.setParent(this.getClass().getClassLoader());
classLoader.setThreadContextLoader();
validateParameters();
final Database[] database = { null };
try {
resourceAccessor = createResourceAccessor(classLoader);
scopeValues.put(Scope.Attr.resourceAccessor.name(), resourceAccessor);
scopeValues.put(Scope.Attr.classLoader.name(), classLoader);
Scope.child(scopeValues, () -> {
database[0] = createDatabaseFromType(databaseType, resourceAccessor);
liquibase = new Liquibase(getChangeLogFile(), resourceAccessor, database[0]);
if (changeLogParameters != null) {
changeLogParameters.applyParameters(liquibase);
}
if (shouldRun()) {
executeWithLiquibaseClassloader();
}
});
} catch (Exception e) {
throw new BuildException("Unable to initialize Liquibase: " + e.getMessage(), e);
} finally {
closeDatabase(database[0]);
classLoader.resetThreadContextLoader();
classLoader.cleanup();
classLoader = null;
}
}
use of liquibase.Liquibase in project liquibase by liquibase.
the class ChangeLogSyncToTagTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Liquibase liquibase = getLiquibase();
OutputStreamWriter writer = null;
try {
FileResource outputFile = getOutputFile();
if (outputFile != null) {
writer = new OutputStreamWriter(outputFile.getOutputStream(), getOutputEncoding());
liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels(), writer);
} else {
liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels());
}
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unable to generate sync SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
} catch (IOException e) {
throw new BuildException("Unable to generate sync SQL. Error creating output writer.", e);
} catch (LiquibaseException e) {
throw new BuildException("Unable to sync change log: " + e.getMessage(), e);
} finally {
FileUtils.close(writer);
}
}
use of liquibase.Liquibase in project liquibase by liquibase.
the class LiquibaseChangeLogSyncSQLMojo method createLiquibase.
@Override
protected Liquibase createLiquibase(Database db) throws MojoExecutionException {
Liquibase liquibase = super.createLiquibase(db);
// Setup the output file writer
try {
if (!migrationSqlOutputFile.exists()) {
// Ensure the parent directories exist
migrationSqlOutputFile.getParentFile().mkdirs();
// Create the actual file
if (!migrationSqlOutputFile.createNewFile()) {
throw new MojoExecutionException("Cannot create the migration SQL file; " + migrationSqlOutputFile.getAbsolutePath());
}
}
outputWriter = getOutputWriter(migrationSqlOutputFile);
} catch (IOException e) {
getLog().error(e);
throw new MojoExecutionException("Failed to create SQL output writer", e);
}
getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
return liquibase;
}
Aggregations