protected void liquibaseUpdate(DataSource ds) throws Exception { PostgresLiquibaseUtils.update(ds, this.changelogResourcePath); }
String latestSnapshotJson = getLatestSnapshotAsJson(latestSnapshotResourcePath); DiffResult diffResult = compareSnapshots(latestSnapshotJson, currentSnapshotJson); if (diffResult.areEqual()) { return true; String changeLogXml = diffToChangeLog(diffResult, currentSnapshot); Path latestChangeLogPath = Paths.get("current-changelog.xml").toAbsolutePath(); logger.severe(String.format("*** Current Liquibase changelog: %s\n%s\n",
private static void update(DataSource ds, String changeLogFile, ResourceAccessor resourceAccessor) throws Exception { // TODO: workaround to resolve locking issue with postgres checkLiquibaseTables(ds); try (Connection conn = ds.getConnection()) { Contexts contexts = new Contexts(""); LabelExpression labels = new LabelExpression(); Liquibase liquibase = new Liquibase(changeLogFile, resourceAccessor, new JdbcConnection(conn)); // Check if update is needed without locking liquibase tables List<ChangeSet> changes = liquibase.listUnrunChangeSets(contexts, labels); if (changes.isEmpty()) { return; } // Release locks on timeout releaseLockOnTimeout(liquibase); // Reset liquibase as it has cached the run change sets during the // listUnrunChangeSets() call which happens before acquiring the update lock and may // miss latest entries ChangeLogHistoryServiceFactory.getInstance().resetAll(); // Update liquibase.update(contexts, labels); } }
protected boolean validateLiquibaseSnapshot(PostgresSchemaManager schemaManager) throws Exception { return PostgresLiquibaseUtils.validateSnapshot(schemaManager.getSnapshot(), this.latestSnapshotResourcePath, true); }
public static void updateFromMemory(DataSource ds, String changelogXml) throws Exception { // Resource accessor to read content from strings ResourceAccessor resourceAccessor = new ResourceAccessor() { @Override public Set<InputStream> getResourcesAsStream(String path) throws IOException { switch (path) { case "changelog.xml": return Collections.singleton( new ByteArrayInputStream(changelogXml.getBytes(Utils.CHARSET))); default: return null; } } @Override public Set<String> list(String relativeTo, String path, boolean includeFiles, boolean includeDirectories, boolean recursive) { return null; } @Override public ClassLoader toClassLoader() { return null; } }; update(ds, "changelog.xml", resourceAccessor); }
public static void update(DataSource ds, String changelogResourceName) throws Exception { update(ds, changelogResourceName, new ClassLoaderResourceAccessor()); }