skip to Main Content

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


  1. Running your sql script after a database installation (or Docker deployment) is something you can do with many (automated or not) tools.

    • Check Ansible to run your SQL scripts.
    • Check querying tools like Datagrip, PgSQL, and others PostgreSQL database clients.
    Login or Signup to reply.
  2. 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:

    <changeSet  id="1"  author="enccne"  runInTransaction="false">
        <sql>CREATE DATABASE myDatabase;</sql>
    </changeSet>
    

    More details here: https://docs.liquibase.com/concepts/changelogs/attributes/run-in-transaction.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search