0

We have a (internal to company, external to project) library (jar) that includes some Liquibase scripts to add tables to a schema to support the functionality of that library.

Using SpringBoot and Maven to run integration tests with H2, we have been using sql files, listed in property files, to initialise the DB.

We want to be able to add data to the tables created by the external (to the project) library for the ITs but finding the tables haven't been created by Liquibase when SpringBoot/SpringData attempts to run the insert statements in our sql files.

Given the errors we're seeing (tables not existing when spring attempts to run the insert.sql files) it looks like spring is executing those files before Liquibase has done its thing.

How can I ensure Liquibase config run by the library to create tables has completed before Spring does it's thing with running sql files specified by the spring.datasource.data property?

We don't really want to include the test data in the library (which was working, but introduced other issued we are trying to work around with liquibase inserting test data into production DB).

DaFoot
  • 1,475
  • 8
  • 29
  • 58

2 Answers2

0

what about using different context for your tests?

so you will have application.properties in your test folder and there you will define another changelog that will include all changelogs that are needed (even from library) and you will also include the .sql file that you are running probably with jpa? Try to look here if that helps.

bilak
  • 4,526
  • 3
  • 35
  • 75
  • I have separate test config (@Configuration and .properties) already. I am currently loading the data sql in this project test hierarchy using a spring.datasource.data property. I'm hoping to avoid introducing Liquibase changelogs into this project (our sql scripts are working well enough for us at the moment) as well as the jar that is using it. – DaFoot Jan 28 '21 at 10:34
0

Current spring doc says:

If you are using a Higher-level Database Migration Tool, like Flyway or Liquibase, you should use them alone to create and initialize the schema. Using the basic schema.sql and data.sql scripts alongside Flyway or Liquibase is not recommended and support will be removed in a future release.

I would rewrite .sql files to liquibase patches.

Conrad
  • 536
  • 5
  • 13