1

I have the following configuration:

├── src
│   ├── main
...
│   │   └── resources
│   │       ├── db
│   │       │   └── changelog
│   │       │       ├── changes
│   │       │       │   ├── db.changelog-1.0.insert-data.xml
│   │       │       │   └── db.changelog-1.0.xml
│   │       │       ├── db.changelog-master.xml
│   │       ├── env-profiles
│   │       │   └── application.yml
...
│   └── test
...
│       └── resources
│           ├── db
│           │   └── changelog
│           │       ├── changes
│           │       │   ├── db.changelog-1.0.insert-data.xml
│           │       │   └── db.changelog-1.0.xml
│           │       ├── db.changelog-master.xml
│           └── env-profiles
│               └── application.yml

Both application.yml in main and test directories contain the same Liquibase settings:

spring:
...
  liquibase:
    enabled: true
    change-log: classpath:db.changelog-master.xml

And this is the db.changelog-master.xml:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
            http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
    <include file="db.changelog-1.0.xml" />
    <include file="db.changelog-1.0.insert-data.xml" />
</databaseChangeLog>

The difference between the changelog files in main and test directories is around the seed data for tests.

When I run my integration tests with @SpringBootTest I can see that the application.yml from test is being picked up, but Liquibase executes the changsets from the main dir rather than from test.

How to configure Spring Boot or Liquibase to make it pick the changeset from test directory when running tests in my current setup?

woj.sierak
  • 513
  • 6
  • 17
  • One workaround is to include the context which will trigger reading a separate changeset, as explained here: https://stackoverflow.com/questions/47036222/how-to-create-liquibase-changeset-for-integration-tests-in-springboot/47038728 but I was wondering whether there is something simple I'm missing that prevents this setup to read changesets from resources/test dir. – woj.sierak Sep 16 '20 at 20:21
  • 1
    your setup is quite messy. You have on classpath two files wich are on path `db/changelog/changes/db.changelog-master.xml` and probably one of them is overriding second one. I would consider changing names of changelogs so for tests I would use sometihng like `db.changelog-master-test.xml` and also change names (or at least directory name) for changes included in `changes` folder. By that you will for sure know which changelog was loaded. – bilak Sep 17 '20 at 17:40

0 Answers0