Jenkins and Maven SQL Plugin for cleaning Postgresql database

How many times did you experienced issue, when you need to clean your database from unused data ?For example, you have a qa server with thousands of rows, which you don’t need anymore, so it’s time to delete them. To clean up your database, someone call separate scripts for each table, someone create-drops database.I decided to delete all tables. To remove all rows, you can use maven sql plugin, which has powerful possibilities for doing work with sql.

Before we start

I don’t want anyone to think, that such module is the best place for storing your database schemas creation.For this purposes there is a good framework called liquibase - it saves migration history and can surely know, what should be updated, and what should not.

Such module is always good for adding additional data into your dev/qa/uat/release environments.

This module can also be very useful, when you want to do some manipulations with database.

Maven SQL plugin

To create maven sql plugin, add plugin into pom.xml build section

This plugin is mapped to install goal and will executes as soon as you will run mvn install command.



As a said before, I use this module for doing database cleaning in my project. The reason I am doint that is that I have migration scripts in liquibase, that, from time to time needs to be reupdated. Due to the fact, that liquibase stores changeset structure, next time, when I will run my updated migration script - I will receive fail. Of course, I know, that this is an issue, because I don’t need to reupdate changeset - I need to write new one, but currently I am not in production - so I want to keep liquibase scripts simple.

I published jenkins job with is-lnu-clean/pom.xml maven pom and mvn install command, so when I need to clean up my database - I do that easily with my jenkins.