DEV Community

Cover image for JaVers: Periodic Maintenance of the Audit Tables
Michael Brizic
Michael Brizic

Posted on • Originally published at linkedin.com

JaVers: Periodic Maintenance of the Audit Tables

This article is about using JaVers for versioning your data object's within your Java application and performing maintenance on the JaVers audit tables that are used to track the changes.

JaVers is meant for storing an audit trail of changes made to an application data model. It's a very nice software product and is very simple to integrate into a Java Spring Boot application. Read here for further.

One day I discovered that the development and testing environments' databases had grown super huge. It turns out that the JaVers audit tables were contributing the most to the overall size.

However, I did not find any out-of-the-box feature that allows one to perform periodic maintenance of the audit tables. As far as I know, the audit tables simply grow and grow, along with all the changes to the data model, ad infinitum. I also did not find any documentation on how to do this.

I opened a GitHub question but it wasn't answered as quickly as I hoped. The development and testing environments' databases were so large that I was suddenly running out of disk space. I thought it might be nice to clean up the audit tables that JaVers uses rather than simply add more disk space since after all, the environments were merely for development and testing.

After studying the source code and the tables I realized that there are a total of four tables that JaVers creates and uses. I also figured out their relationships to one another and how cleaning up the data would be executed.

In my particular case, the database is MySQL and runs inside of a Docker container. So my solution includes interacting with the database via the Docker container.

The first part that I'll share below are the tables and the commands needed to reduce the size of data that they store. It requires that you choose a data for which all data from that point going backwards will be removed. The data provided should be given as yyyy-MM-dd.

Image description

The above would be saved to a file named cleanup-javers.sql. Then, the commands of the SQL file will be executed according to the following convenience script:

Image description

For convenience, I also added the above to files and hosted them in my GitHub located here.

Let me know if some corrections need to be made or enhancements. Thanks!

Top comments (0)