I have defined liquibase migrations that don’t pass because I have to release schema.sql first, which is to be enforced as part of integration tests.
Unfortunately as embedded postgres starts (https://github.com/zonkyio/embedded-postgres) liquibase migrations start immediately after that and schema.sql is ignored.
schema.sql is located in test/resources/schema.sql.
I’m looking for a way to run several SQL queries (create database, create role) that will be run each time embedded postgres is run in tests.
I tried with both schema.sql and data.sql. I’d like to avoid importing additional libraries that would just enforce this (like Pre-Liquibase).
2
Answers
Running your sql script after a database installation (or Docker deployment) is something you can do with many (automated or not) tools.
You can just add the SQL commands at the very beginning of you Liquibase migration scripts. To be executed only in test environment.
As you stated in the comment the Postgres CREATE DATABASE command can’t run in a transaction. There is an attribute
runInTransaction
in the Liquibase changeset configuration to run a changeset without transaction:More details here: https://docs.liquibase.com/concepts/changelogs/attributes/run-in-transaction.html