private void generateChangeLog(final Database database, final CatalogAndSchema catalogAndSchema, final DiffToChangeLog changeLogWriter, PrintStream outputStream, final Set<Class<? extends DatabaseObject>> compareTypes) throws DatabaseException, IOException, ParserConfigurationException { @SuppressWarnings("unchecked") final SnapshotControl snapshotControl = new SnapshotControl(database, compareTypes.toArray(new Class[compareTypes.size()])); final CompareControl compareControl = new CompareControl(new CompareControl.SchemaComparison[]{ new CompareControl.SchemaComparison(catalogAndSchema, catalogAndSchema)}, compareTypes); final CatalogAndSchema[] compareControlSchemas = compareControl .getSchemas(CompareControl.DatabaseRole.REFERENCE); try { final DatabaseSnapshot referenceSnapshot = SnapshotGeneratorFactory.getInstance() .createSnapshot(compareControlSchemas, database, snapshotControl); final DatabaseSnapshot comparisonSnapshot = SnapshotGeneratorFactory.getInstance() .createSnapshot(compareControlSchemas, null, snapshotControl); final DiffResult diffResult = DiffGeneratorFactory.getInstance() .compare(referenceSnapshot, comparisonSnapshot, compareControl); changeLogWriter.setDiffResult(diffResult); changeLogWriter.print(outputStream); } catch (InvalidExampleException e) { throw new UnexpectedLiquibaseException(e); } }
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(Index.class)) { return; } if (foundObject instanceof Table) { Table table = (Table) foundObject; org.hibernate.mapping.Table hibernateTable = findHibernateTable(table, snapshot); if (hibernateTable == null) { return; } Iterator indexIterator = hibernateTable.getIndexIterator(); while (indexIterator.hasNext()) { org.hibernate.mapping.Index hibernateIndex = (org.hibernate.mapping.Index) indexIterator.next(); Index index = new Index(); index.setTable(table); index.setName(hibernateIndex.getName()); Iterator columnIterator = hibernateIndex.getColumnIterator(); while (columnIterator.hasNext()) { org.hibernate.mapping.Column hibernateColumn = (org.hibernate.mapping.Column) columnIterator.next(); index.getColumns().add(new Column(hibernateColumn.getName()).setRelation(table)); } LOG.info("Found index " + index.getName()); table.getIndexes().add(index); } } }
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(Table.class)) { return; } if (foundObject instanceof Schema) { Schema schema = (Schema) foundObject; HibernateDatabase database = (HibernateDatabase) snapshot.getDatabase(); Configuration cfg = database.getConfiguration(); Iterator<org.hibernate.mapping.Table> tableMappings = cfg.getTableMappings(); while (tableMappings.hasNext()) { org.hibernate.mapping.Table hibernateTable = tableMappings.next(); if (hibernateTable.isPhysicalTable()) { Table table = new Table().setName(hibernateTable.getName()); table.setSchema(schema); LOG.info("Found table " + table.getName()); schema.addDatabaseObject(table); } } } } }
public static String createDatabaseSnapshotAsString(DataSource ds) throws LiquibaseException, SQLException { try (Connection conn = ds.getConnection()) { Database database = DatabaseFactory.getInstance() .findCorrectDatabaseImplementation(new JdbcConnection(conn)); DatabaseSnapshot currentSnapshot = SnapshotGeneratorFactory .getInstance().createSnapshot(database.getDefaultSchema(), database, new SnapshotControl(database)); return SnapshotSerializerFactory.getInstance().getSerializer("json") .serialize(currentSnapshot, true); } } }
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(Sequence.class)) { return;
private void generateChangeLog(final Database database, final CatalogAndSchema catalogAndSchema, final DiffToChangeLog changeLogWriter, PrintStream outputStream, final Set<Class<? extends DatabaseObject>> compareTypes) throws DatabaseException, IOException, ParserConfigurationException { @SuppressWarnings({"unchecked", "rawtypes"}) final SnapshotControl snapshotControl = new SnapshotControl(database, compareTypes.toArray(new Class[compareTypes.size()])); final CompareControl compareControl = new CompareControl(new CompareControl.SchemaComparison[]{ new CompareControl.SchemaComparison(catalogAndSchema, catalogAndSchema)}, compareTypes); final CatalogAndSchema[] compareControlSchemas = compareControl .getSchemas(CompareControl.DatabaseRole.REFERENCE); try { final DatabaseSnapshot referenceSnapshot = SnapshotGeneratorFactory.getInstance() .createSnapshot(compareControlSchemas, database, snapshotControl); final DatabaseSnapshot comparisonSnapshot = SnapshotGeneratorFactory.getInstance() .createSnapshot(compareControlSchemas, null, snapshotControl); final DiffResult diffResult = DiffGeneratorFactory.getInstance() .compare(referenceSnapshot, comparisonSnapshot, compareControl); changeLogWriter.setDiffResult(diffResult); changeLogWriter.print(outputStream); } catch (InvalidExampleException e) { throw new UnexpectedLiquibaseException(e); } }
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(UniqueConstraint.class)) { return;
catalog = sourceSchema.getCatalog(); SnapshotControl snapshotControl = new SnapshotControl(liquibaseDatabase); DatabaseSnapshot snapshot = dsgf.createSnapshot(new CatalogAndSchema(catalog, schemaName), liquibaseDatabase, snapshotControl);
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(PrimaryKey.class)) { return;
catalog = sourceSchema.getCatalog(); SnapshotControl snapshotControl = new SnapshotControl(liquibaseDatabase); DatabaseSnapshot snapshot = dsgf.createSnapshot(new CatalogAndSchema(catalog, schemaName), liquibaseDatabase, snapshotControl);
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(Table.class)) { return;
protected void updateChangeSet(Liquibase liquibase, Connection connection, Writer exportWriter) throws LiquibaseException, SQLException { String changelog = liquibase.getChangeLogFile(); Database database = liquibase.getDatabase(); Table changelogTable = SnapshotGeneratorFactory.getInstance().getDatabaseChangeLogTable(new SnapshotControl(database, false, Table.class, Column.class), database);
@Override protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (!snapshot.getSnapshotControl().shouldInclude(ForeignKey.class)) { return;