Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

programatically call liquibase for data diff?

$
0
0
Hi, I have read a similar post, https://forum.liquibase.org/topic/is-it-possible-to-generatechangelog-difftypes-data-programatically, for generating data diff changelogs in java/junit code. I tried a similar way in my code with Liquibase 3.4.2 and set DiffTypes in code (code attached). However it did not work.

I am not sure if I set the DiffTypes correctly and wonder if this version of Library supports data diff or which version is capable of? Thanks.

- Diff DB
  1.                 String types = "tables,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints,data";

  2. CompareControl compareControl = new CompareControl(null, types);
  3. DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, null, compareControl);
  4. ByteArrayOutputStream output = new ByteArrayOutputStream();

  5. new DiffToChangeLog(diffResult, new DiffOutputControl(false, true, true)).print(new PrintStream(output));
- Diff Snapshot
  1. DatabaseSnapshot originalSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(database.getDefaultSchema(), database, new SnapshotControl(database, types));
  2. Liquibase liquibase = new Liquibase("db/changelog/db.changelog-newdata.xml", new ClassLoaderResourceAccessor(), database);
  3. // update DB data
  4.         liquibase.update("");
  5.         DatabaseSnapshot migratedSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(database.getDefaultSchema(), database, new SnapshotControl(database, types));
  6.         DiffResult finalDiffResult = DiffGeneratorFactory.getInstance().compare(originalSnapshot, migratedSnapshot, compareControl);
  7.          new DiffToChangeLog(finalDiffResult, new DiffOutputControl(false, true, true)).print(new PrintStream(output));



Viewing all articles
Browse latest Browse all 2993

Trending Articles