Alambique Ancora: Liquibase
Well, this week happened what I called database twist. I’ve been working with MySQL for a long time. As I said, the work with the AA is to learn new things or learn things better, so I changed the database.
MySQL is a interesting database, but a more interesting database is PostgreSQL. I already worked with it, but it was some time ago. So, during this week I decided to continue this project using PostgreSQL instead of MySQL. Also, PostgreSQL has a more advanced set of features.
Let’s execute the command to prepare our PostgreSQL container.
docker run -p 5432:5432 --name aa-postgres -e POSTGRES_PASSWORD=a1b2c3d4 -d postgres:latest
Done!
Liquibase
One of the challenges with databases is to apply and keep track of changes. Liquibase allows an easiest database evolution and maintenance, keeping all the changes into XML|YAML|JSON|SQL files. One cool thing about Liquibase is that allow us to start a fresh database and to apply the whole changelog leading to the latest state of our database.
Liquibase also supports various databases.
In this specific case, the chosen file format was the YAML. I liked this format in the first time I saw it. I think it is much simpler than XML.
To keep all database changes centralized, I created a database project on GitHub. Late on this project we’ll put it into our build and deploy process to apply all changes to our environment automatically.
Build tool
I’ve been working with Maven on a daily basis. So, for run this database project I think would be great to use another build tool. Gradle, for example. This tool is open source and was designed upon the concepts of Ant and Maven and introduces a Groovy-based domain-specific language (DSL) instead of XML used by Maven.
The Liquibase configuration in the Gradle build file is quite simple. Each activity can be a specific environment and during the build cycle we can specify which activity or activities we want to run thought the runList parameter.
After the clone of the database repository on GitHub, in the base directory the command below should be executed to apply all changes to our database.
gradle update -PrunList='development'
The parameter runList specify which activity we desire to apply changes to. In our case, the development is the primary environment. If we wanted specify more than one activity, we should use a comma to separe the activities.
gradle update -PrunList='development,homologation'
So, that’s it
For now. In the next post I’ll show some Java code. I hope.
See ya!