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
- String types = "tables,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints,data";
- CompareControl compareControl = new CompareControl(null, types);
- DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, null, compareControl);
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- new DiffToChangeLog(diffResult, new DiffOutputControl(false, true, true)).print(new PrintStream(output));
- Diff Snapshot
- DatabaseSnapshot originalSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(database.getDefaultSchema(), database, new SnapshotControl(database, types));
- Liquibase liquibase = new Liquibase("db/changelog/db.changelog-newdata.xml", new ClassLoaderResourceAccessor(), database);
- // update DB data
- liquibase.update("");
- DatabaseSnapshot migratedSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(database.getDefaultSchema(), database, new SnapshotControl(database, types));
- DiffResult finalDiffResult = DiffGeneratorFactory.getInstance().compare(originalSnapshot, migratedSnapshot, compareControl);
- new DiffToChangeLog(finalDiffResult, new DiffOutputControl(false, true, true)).print(new PrintStream(output));