DEV Community

Rohith Kunnath
Rohith Kunnath

Posted on

Test Liquibase migration changes in the local environment using Docker

I am publishing this article because recently found out we had problems in the pre-live environment related to some liquibase migration issue.

Then I was thinking maybe this could be because of not testing properly in our local environment or not knowing how to do testing itself.

Unfortunately, some commands use java-maven, but I am sure there are alternatives for these statements.

Maybe the following could help someone :)

Prerequisites :

  • Docker

Steps to do:

  • Docker-compose file content can be copied from here - https://hub.docker.com/_/postgres
  • docker-compose up - Runs a container with Postgress DB running inside
  • docker ps - Lists the container details
  • Do an export of schema from prelive or test environment.
  • docker exec -it {replace_with_container_id} bash - You can login to the container and import the exported schema.
  • From your local, open changelog.xml and comment out changes other than yours.
  • Change liquibase configuration inside pom.xml to local postgres configuration.
  • Run the command mvn liquibase:update to see your changes being applied.

Tips for postgres newbie:

Once you login to the docker container using STEP-5 mentioned in Steps to do,

  • execute command psql -U postgres - "postgres" is the username used in the docker-compose content.

  • \c {db_name} - connect to a db

  • \dt - show tables in that database

  • \d {table_name} - describe table

Thank you for reading and I am happy if I could help someone.

Top comments (0)