Generally speaking, I’d expect a CI system to not maintain database state across runs, especially as there’s no guarantee it’s run on the same machine different times. I.e., on each run, a new database should be spun up, populated, tested, and then destroyed. In any case, I would look at how we test things with MySQL and use that as a model.
In addition to what Ian has said, just in case you find the conversation here useful: https://issues.openmrs.org/browse/TRUNK-4821
I went through the current CI plan https://ci.openmrs.org/chain/admin/config/defaultStages.action?buildKey=TRUNK-MASTER and it seems to me that we are not running the liquibase change sets against MySQL db. So, it will be the first time that we will be running the liquibase change sets.
I have the following job structure in mind that will be run after the integration tests :
1.DOCKER TASK - Task description - Pull PostgreSQL docker Image
Command - Pull a Docker image from a Docker registry
Registry - Docker Hub
Repository - postgres:12
2.SCRIPT TASK - Task description - PostgreSQL Container setup
Interpreter - Shell
Script location - Inline
Script body - docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 postgres
3.MAVEN TASK- Task description - Liquibase Schema setup
Goal - liquibase:update -Dliquibase.url=jdbc:postgresql://localhost:5432/postgres -Dliquibase.changelogSchemaName=postgres-Dliquibase.username=postgres -Dliquibase.password=docker -Dliquibase.driver=org.postgresql.Driver -Dliquibase.changeLogFile=location/to/liquibase-schema-only-2.3.x.xml -Djava.awt.headless=true -Dliquibase.promptOnNonLocalDatabase=false
Build JDK - 1.8
Advanced Options -> Override project file - liquibase/pom.xml
4.MAVEN TASK- Task description - Liquibase Core Data setup
Goal - liquibase:update -Dliquibase.url=jdbc:postgresql://localhost:5432/postgres -Dliquibase.changelogSchemaName=postgres-Dliquibase.username=postgres -Dliquibase.password=docker -Dliquibase.driver=org.postgresql.Driver -Dliquibase.changeLogFile=location/to/liquibase-core-data-2.3.x.xml -Djava.awt.headless=true -Dliquibase.promptOnNonLocalDatabase=false
Build JDK - 1.8
Advanced Options -> Override project file - liquibase/pom.xml
5.MAVEN TASK- Task description - Liquibase Update To Latest setup
Goal - liquibase:update -Dliquibase.url=jdbc:postgresql://localhost:5432/postgres -Dliquibase.changelogSchemaName=postgres-Dliquibase.username=postgres -Dliquibase.password=docker -Dliquibase.driver=org.postgresql.Driver -Dliquibase.changeLogFile=location/to/liquibase-update-to-latest-2.4.x.xml -Djava.awt.headless=true -Dliquibase.promptOnNonLocalDatabase=false
Build JDK - 1.8
Advanced Options -> Override project file - liquibase/pom.xml
6.FINAL TASK (should be run even if above tasks fail)
SCRIPT - docker stop pg-docker
I have added a Bamboo CI job to run liquibase change sets against PostgreSQL at https://ci.openmrs.org/browse/TRUNK-MASTER . Here is the link to ticket : https://issues.openmrs.org/browse/TRUNK-5960 . Ticket description holds the job details. Please review it.