I have the following script, that works. It starts a docker mysql container, and initializes the database before running several executions of the liquibase plugin that run different stuff.
function die { mvn docker:stop ; exit 1; }
function initializeDatabase {
docker exec -it mysql-1 mysql -uroot -proot \
-e "DROP USER IF EXISTS 'myuser'@'%';" \
-e "DROP DATABASE IF EXISTS mydb;" \
-e "CREATE DATABASE mydb;" \
-e "CREATE USER 'myuser'@'%' IDENTIFIED WITH mysql_native_password BY 'mypassword';" \
-e "GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%';"
}
mvn docker:start && sleep 10
initializeDatabase || die
mvn liquibase:update@execution1 || die
initializeDatabase || die
mvn liquibase:update@execution2 || die
initializeDatabase || die
mvn liquibase:update@execution3 || die
initializeDatabase || die
mvn liquibase:update@execution4 || die
initializeDatabase || die
mvn liquibase:update@execution5 || die
initializeDatabase || die
mvn liquibase:update@execution6 || die
mvn docker:stop
It occurs to me that I could just have the docker start happen during the pre-integration-test phase and have all the liquibase executions run during the integration-test phase and then have the docker stop in the post-integration-test phase. However, I don't know how to initialize the database using the root user before each execution of the liquibase plugin.
Any thoughts on how I could do this so that it would just happen seamlessly as part of the maven build lifecycle? Thanks!