use of liquibase.snapshot.DatabaseSnapshot in project liquibase by liquibase.
the class SequenceExistsPrecondition method check.
@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
DatabaseSnapshot snapshot;
Schema schema = new Schema(getCatalogName(), getSchemaName());
try {
if (!SnapshotGeneratorFactory.getInstance().has(new Sequence().setName(getSequenceName()).setSchema(schema), database)) {
throw new PreconditionFailedException("Sequence " + database.escapeSequenceName(getCatalogName(), getSchemaName(), getSequenceName()) + " does not exist", changeLog, this);
}
} catch (LiquibaseException e) {
throw new PreconditionErrorException(e, changeLog, this);
}
}
use of liquibase.snapshot.DatabaseSnapshot in project liquibase by liquibase.
the class Liquibase method generateChangeLog.
public void generateChangeLog(CatalogAndSchema catalogAndSchema, DiffToChangeLog changeLogWriter, PrintStream outputStream, ChangeLogSerializer changeLogSerializer, Class<? extends DatabaseObject>... snapshotTypes) throws DatabaseException, IOException, ParserConfigurationException {
Set<Class<? extends DatabaseObject>> finalCompareTypes = null;
if (snapshotTypes != null && snapshotTypes.length > 0) {
finalCompareTypes = new HashSet<Class<? extends DatabaseObject>>(Arrays.asList(snapshotTypes));
}
SnapshotControl snapshotControl = new SnapshotControl(this.getDatabase(), snapshotTypes);
CompareControl compareControl = new CompareControl(new CompareControl.SchemaComparison[] { new CompareControl.SchemaComparison(catalogAndSchema, catalogAndSchema) }, finalCompareTypes);
// compareControl.addStatusListener(new OutDiffStatusListener());
DatabaseSnapshot originalDatabaseSnapshot = null;
try {
originalDatabaseSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(compareControl.getSchemas(CompareControl.DatabaseRole.REFERENCE), getDatabase(), snapshotControl);
DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(originalDatabaseSnapshot, SnapshotGeneratorFactory.getInstance().createSnapshot(compareControl.getSchemas(CompareControl.DatabaseRole.REFERENCE), null, snapshotControl), compareControl);
changeLogWriter.setDiffResult(diffResult);
if (changeLogSerializer != null) {
changeLogWriter.print(outputStream, changeLogSerializer);
} else {
changeLogWriter.print(outputStream);
}
} catch (InvalidExampleException e) {
throw new UnexpectedLiquibaseException(e);
}
}
use of liquibase.snapshot.DatabaseSnapshot in project collect by openforis.
the class LiquidbaseDatabaseSnapshotBuilder method createSnapshot.
public synchronized DatabaseSnapshot createSnapshot(RelationalSchema relationalSchema, boolean dbSupportsFKs) throws DatabaseException {
this.schema = relationalSchema;
UnsupportedDatabase db = new UnsupportedDatabase();
snapshot = new DatabaseSnapshot(db, null);
createTables();
createPKIndexes();
if (dbSupportsFKs) {
createForeignKeys();
}
return snapshot;
}
use of liquibase.snapshot.DatabaseSnapshot 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.snapshot.DatabaseSnapshot in project liquibase by liquibase.
the class MySQLIntegrationTest method snapshot.
@Test
public void snapshot() throws Exception {
if (getDatabase() == null) {
return;
}
runCompleteChangeLog();
DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(getDatabase().getDefaultSchema(), getDatabase(), new SnapshotControl(getDatabase()));
System.out.println(snapshot);
}
Aggregations