Search in sources :

Example 1 with DatabaseSnapshot

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);
    }
}
Also used : Schema(liquibase.structure.core.Schema) Sequence(liquibase.structure.core.Sequence) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot)

Example 2 with DatabaseSnapshot

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);
    }
}
Also used : InvalidExampleException(liquibase.snapshot.InvalidExampleException) DatabaseObject(liquibase.structure.DatabaseObject) CompareControl(liquibase.diff.compare.CompareControl) DiffResult(liquibase.diff.DiffResult) SnapshotControl(liquibase.snapshot.SnapshotControl) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 3 with DatabaseSnapshot

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;
}
Also used : UnsupportedDatabase(liquibase.database.core.UnsupportedDatabase) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot)

Example 4 with DatabaseSnapshot

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);
    }
}
Also used : Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) CompareControl(liquibase.diff.compare.CompareControl) SnapshotGeneratorFactory(liquibase.snapshot.SnapshotGeneratorFactory) LiquibaseException(liquibase.exception.LiquibaseException) BuildException(org.apache.tools.ant.BuildException) CatalogAndSchema(liquibase.CatalogAndSchema) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) SnapshotControl(liquibase.snapshot.SnapshotControl)

Example 5 with DatabaseSnapshot

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);
}
Also used : DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) SnapshotControl(liquibase.snapshot.SnapshotControl) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Aggregations

DatabaseSnapshot (liquibase.snapshot.DatabaseSnapshot)28 SnapshotControl (liquibase.snapshot.SnapshotControl)20 Test (org.junit.Test)13 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)7 Column (liquibase.structure.core.Column)7 Table (liquibase.structure.core.Table)7 DiffResult (liquibase.diff.DiffResult)6 CompareControl (liquibase.diff.compare.CompareControl)6 CatalogAndSchema (liquibase.CatalogAndSchema)5 Liquibase (liquibase.Liquibase)5 Database (liquibase.database.Database)5 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)5 DatabaseObject (liquibase.structure.DatabaseObject)5 DatabaseException (liquibase.exception.DatabaseException)4 LiquibaseException (liquibase.exception.LiquibaseException)4 Schema (liquibase.structure.core.Schema)4 DiffOutputControl (liquibase.diff.output.DiffOutputControl)3 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)3 RawSqlStatement (liquibase.statement.core.RawSqlStatement)3 IOException (java.io.IOException)2