Setting up a Liquibase project with Maven and PostgreSQL
The purpose of this document is to guide you through the process of creating a new Maven project with
PostgreSQL on a Linux/Unix/Mac machine. In this tutorial, you will generate an example project and follow
the instructions to apply and learn concepts associated with creating new Liquibase Projects within Maven.
To create a Liquibase project within Maven that uses a PostgreSQL database, begin with the following steps:
Create a new project folder and name it MavenPostgreSQL.
Create a new plain-text file named dbchangelog.xml in the MavenPostgeSQL directory. This file will be your changelog, a file that will keep track of
all the changes you make to your database structure. You can learn more about them on the Database Change Log File page.
In this tutorial, you will manually add a single change. We will start with an empty changelog file.
Open the dbchangelog.xml file and update it with the following text. This is a basic empty changelog file.
Create another plain text file in the same directory, named liquibase.properties
Edit the liquibase.properties file to add the following properties:
Note: If you have a Liquibase Pro key and want to apply it to your project, add the following property to your liquibase.properties file.
liquibaseProLicenseKey: <paste license key>
Add a changeset to the changelog.
In the dbchangelog.xml file line 9 to 20 add a new changeset. This changeset will have one change in it, to create a table named “department”.
Now, we create the maven POM file for the project. Create a new plain-text file in the same directory named pom.xml.
Edit the pom.xml file and update it to have the following contents:
Open the command prompt and navigate to the MavenPostgreSQL directory.
Run the following command: mvn liquibase:update
From a database UI Tool, for example: “pgAdmin” check your database changes under “MYDATABASE”.
You should see a new “department” table added to the database.
Also, you should see two more tables:
DATABASECHANGELOG - This table keeps a record of all the changesets that have been deployed. The next time you run the update command, the
changesets in the changelog will be compared with the DATABASECHANGELOG tracking table, and only the new changesets not
found in the DATABASECHANGELOG will be deployed. You will notice that a new row was created in that table with the changeset
information we have just deployed.
DATABASECHANGELOGLOCK - This table is used internally by Liquibase to manage access to the changelog table during deployment.