Question

Testers are updating data through the app

I am working with an application where the app is changing rapidly, but at the same time, the testers need to build test and certification data. This data is being created by accessing the app directly, rather than writing SQL statements.

So, I have changesets coming in from the developers and data changes being applied through the application by testers at the same time.

I have wired up liquibase to handle running the changesets written by the developers, but I'm having difficulties figuring out the cleanest way to track and preserve data changes by the testers.

Possible workflow

Based on using liquibase through the entire process, I'm thinking I need a workflow like:

  1. Start with the latest clean database
  2. Run liquibase update
  3. Snapshot or tag the database for differencing later
  4. Let the testers hack away through the app.
  5. If the testers approve the changes, upon promotion:
    1. generate a data diff as a changeset
    2. include the data changeset in the master update list
    3. on this VM, record the changeset as already ran
    4. commit to scm
  6. Repeat

Questions

  1. Is there a way to use liquibase to get a true data diff, and not a full data export? It seems that generateChangeLog is the only tool in the diffs that allows setting the --diff-type="data" flag and value, but the documentation also makes that seem that it won't diff, it just dumps all of the data.

  2. If yes,

    1. can you provide a sample call? I have the url & referenceURL figured out and stored in a liquibase.properties file, I just need to know which command and flags to pass.

    2. can it be used against a tag instead of having to create a backup of the database? (step 3 in the workflow)

  3. If no,

    1. has anyone seen a good tutorial or howto showing the orchestration between liquibase and dbUnit updates?

    2. How do you handle the situation where the data export no longer fits the schema? For example, FullName split => FirstName and LastName; liquibase can handle this, but I would think that I would need to orchestrate running updates between liquibase and dbUnit, otherwise the diff of dbUnit will be invalid?

Any guidance, tips, past experiences or gotchas to watch out for would be greatly appreciated.

Was it helpful?

Solution

No, liquibase does not support a data diff, only a full data dump.

I have seen http://ljnelson.github.io/liquiunit/ which may help you with dbunit integration, but using dbunit or any other data load tool to manage your data will run into schema incompatibilities like you suggest.

What I would suggest doing is to have "test data load" changeSets that are added into your changeLog to build up your test data as you go along.

For example:

<changeSet id="1" author="x">
   <createTable name="a"../>
</changeSet>
<changeSet id="2" author="x">
   <createTable name="b"../>
</changeSet>

<changeSet id="3" author="x" context="test">
   <sqlFile path="data-dump.1.sql">
</changeSet>

<changeSet id="4" author="x">
   <renameColumn oldColumnName="s" newColumnName="t"../>
</changeSet>

<changeSet id="5" author="x" context="test">
   <sqlFile path="data-dump.2.sql">
</changeSet>

You see it creates an initial structure and then loads a round of QA's data into the database with the database structure as it is after changeset 2. Notice the use of contexts so the test data isn't loaded into production.

After the test data are more structure changes and then another round of additional QA data. The new data doesn't re-create data-dump.1.sql but is in addition to it. Since data-dump.1.sql is always ran before changeSet 4, it doesn't have to be updated as the schema changes.

The big problem, though, is how to extract your test data as QA is building it up. If they are adding it through your application, the easiest approach may be to use something like p6spy to automatically collect all the SQL executed in your application and then just copy it into your data-dump.X.sql files.

OTHER TIPS

As an alternative to my other answer, you can have a full dump of your database (use liquibase generateChangeLog diffTypes=data or your standard database backup tool) which you create from the QA-built database and move along your changelog file.

Step 1:

Create your database

<changeSet id="1" author="x">
   <createTable name="a"../>
</changeSet>
<changeSet id="2" author="x">
   <createTable name="b"../>
</changeSet>

Step 2

QA creates database then makes a backup which is included in the changelog file.

<changeSet id="1" author="x">
   <createTable name="a"../>
</changeSet>
<changeSet id="2" author="x">
   <createTable name="b"../>
</changeSet>
<changeSet id="testdata-1" author="x" context="test">
    <sqlFile path="data-dump.sql">
</changeSet>

Step 3

There are schema changes that don't require new test data, keep adding to the changelog file. The test data is migrated along and matches your needed schema.

<changeSet id="1" author="x">
   <createTable name="a"../>
</changeSet>
<changeSet id="2" author="x">
   <createTable name="b"../>
</changeSet>
<changeSet id="testdata-1" author="x" context="test">
    <sqlFile path="data-dump.sql">
</changeSet>
<changeSet id="4" author="x">
   <renameColumn oldColumnName="s" newColumnName="t"../>
</changeSet>

Step 4

When QA needs additional data, they add what they want using the app then make a new full backup and move the testdata changeset to the end

<changeSet id="1" author="x">
   <createTable name="a"../>
</changeSet>
<changeSet id="2" author="x">
   <createTable name="b"../>
</changeSet>
<changeSet id="4" author="x">
   <renameColumn oldColumnName="s" newColumnName="t"../>
</changeSet>
<changeSet id="testdata-1" author="x" context="test">
    <sqlFile path="data-dump.sql">
</changeSet>

This process does require you to drop your dev/test databases to get the new test data or you will get insert conflicts, but depending on your workflow it may work for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top