public static void main(String[] args) { VerticaDatabase verticaDatabase = new VerticaDatabase(); liquibase.database.DatabaseFactory.getInstance().register(verticaDatabase); liquibase.snapshot.SnapshotGeneratorFactory.getInstance() .unregister(UniqueConstraintSnapshotGenerator.class); ChangeGeneratorFactory.getInstance().unregister(MissingColumnChangeGenerator.class); Properties myProp = new Properties(); String defaultCatalogName = "yaron_secondary"; String defaultSchemaName = defaultCatalogName; String password = defaultCatalogName + "_123"; String changeLogFilePath = "c:\\liquibaseChangeSet.xml"; String dataOutputDirectory = "c:\\liquibase_output"; String connectionString = "jdbc:vertica://mydphdb0082.hpswlabs.adapps.hp.com:5433/eummobile"; String changeSetAuthor = "jony"; myProp.put("user", defaultCatalogName); myProp.put("password", password); Connection conn = null; try { File changeLogFile = new File(changeLogFilePath); changeLogFile.delete(); conn = DriverManager.getConnection(connectionString, myProp); conn.setAutoCommit(false); DatabaseConnection dc = new JdbcConnection(conn); verticaDatabase.setConnection(dc); String diffTypes = null; String changeSetContext = null; boolean includeCatalog = false; // Boolean.parseBoolean(getCommandParam("includeCatalog", "false")); boolean includeSchema = false; // Boolean.parseBoolean(getCommandParam("includeSchema", "false")); boolean includeTablespace = false; // Boolean.parseBoolean(getCommandParam("includeTablespace", "false")); DiffOutputControl diffOutputControl = new DiffOutputControl(includeCatalog, includeSchema, includeTablespace); CommandLineUtils.doGenerateChangeLog( changeLogFilePath, verticaDatabase, defaultCatalogName, defaultSchemaName, StringUtils.trimToNull(diffTypes), StringUtils.trimToNull(changeSetAuthor), StringUtils.trimToNull(changeSetContext), StringUtils.trimToNull(dataOutputDirectory), diffOutputControl); postChangeSetGenerationProcessing(changeLogFile); } catch (Exception e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }
@Override public Change[] fixMissing( DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) { List<Change> returnList = new ArrayList<Change>(); UniqueConstraint uc = (UniqueConstraint) missingObject; if (uc.getTable() == null) { return null; } AddUniqueConstraintChange change = new AddUniqueConstraintChange(); change.setTableName(uc.getTable().getName()); if (uc.getBackingIndex() != null && control.getIncludeTablespace()) { change.setTablespace(uc.getBackingIndex().getTablespace()); } if (control.getIncludeCatalog()) { change.setCatalogName(uc.getTable().getSchema().getCatalogName()); } if (control.getIncludeSchema()) { change.setSchemaName(uc.getTable().getSchema().getName()); } change.setConstraintName(uc.getName()); change.setColumnNames(uc.getColumnNames()); change.setDeferrable(uc.isDeferrable() ? Boolean.TRUE : null); change.setInitiallyDeferred(uc.isInitiallyDeferred() ? Boolean.TRUE : null); change.setDisabled(uc.isDisabled() ? Boolean.TRUE : null); if (comparisonDatabase instanceof OracleDatabase) { Index backingIndex = uc.getBackingIndex(); if (backingIndex != null && backingIndex.getName() != null) { Change[] changes = ChangeGeneratorFactory.getInstance() .fixMissing(backingIndex, control, referenceDatabase, comparisonDatabase); if (changes != null) { returnList.addAll(Arrays.asList(changes)); change.setForIndexName(backingIndex.getName()); Schema schema = backingIndex.getSchema(); if (schema != null) { if (control.getIncludeCatalog()) { change.setForIndexCatalogName(schema.getCatalogName()); } if (control.getIncludeSchema()) { change.setForIndexSchemaName(schema.getName()); } } } } } Index backingIndex = uc.getBackingIndex(); // if (backingIndex == null) { // Index exampleIndex = new Index().setTable(uc.getTable()); // for (String col : uc.getColumns()) { // exampleIndex.getColumns().add(col); // } // control.setAlreadyHandledMissing(exampleIndex); // } else { control.setAlreadyHandledMissing(backingIndex); // } returnList.add(change); return returnList.toArray(new Change[returnList.size()]); }
@Override public Change[] fixMissing( DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) { List<Change> returnList = new ArrayList<Change>(); PrimaryKey pk = (PrimaryKey) missingObject; AddPrimaryKeyChange change = new AddPrimaryKeyChange(); change.setTableName(pk.getTable().getName()); if (control.getIncludeCatalog()) { change.setCatalogName(pk.getTable().getSchema().getCatalogName()); } if (control.getIncludeSchema()) { change.setSchemaName(pk.getTable().getSchema().getName()); } change.setConstraintName(pk.getName()); change.setColumnNames(pk.getColumnNames()); if (control.getIncludeTablespace()) { change.setTablespace(pk.getTablespace()); } if (referenceDatabase instanceof MSSQLDatabase && pk.getBackingIndex() != null && pk.getBackingIndex().getClustered() != null && !pk.getBackingIndex().getClustered()) { change.setClustered(false); } if (comparisonDatabase instanceof OracleDatabase || (comparisonDatabase instanceof DB2Database && pk.getBackingIndex() != null && !comparisonDatabase.isSystemObject(pk.getBackingIndex()))) { Index backingIndex = pk.getBackingIndex(); if (backingIndex != null && backingIndex.getName() != null) { try { if (!control.getIncludeCatalog() && !control.getIncludeSchema()) { CatalogAndSchema schema = comparisonDatabase.getDefaultSchema().customize(comparisonDatabase); backingIndex .getTable() .setSchema( schema.getCatalogName(), schema .getSchemaName()); // set table schema so it is found in the correct schema } if (referenceDatabase.equals(comparisonDatabase) || !SnapshotGeneratorFactory.getInstance().has(backingIndex, comparisonDatabase)) { Change[] fixes = ChangeGeneratorFactory.getInstance() .fixMissing(backingIndex, control, referenceDatabase, comparisonDatabase); if (fixes != null) { for (Change fix : fixes) { if (fix != null) { returnList.add(fix); } } } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } change.setForIndexName(backingIndex.getName()); Schema schema = backingIndex.getSchema(); if (schema != null) { if (control.getIncludeCatalog()) { change.setForIndexCatalogName(schema.getCatalogName()); } if (control.getIncludeSchema()) { change.setForIndexSchemaName(schema.getName()); } } } } control.setAlreadyHandledMissing(pk.getBackingIndex()); returnList.add(change); return returnList.toArray(new Change[returnList.size()]); }