Using Liquibase in multi module project
Asked Answered
N

2

9

I have two modules (editor and engine) that work with a common database. For deployment of scripts I want to use liquibase. I do not want to duplicate the same scripts in two places, and I want to manage them in one place. To do this, I created a separate module (database-structure) that only contains my scripts and the parameter spring .liquibase.change-log=classpath:db/changelog/db.changelog-master.xml. I have add this module (database-structure) as a dependency to my other modules. The final structure is as follows (classes are omitted for compactness):

D:\PROJECTS\MY-PROJECT
├───database-structure
│   │   pom.xml
│   │
│   └───src
│       ├───main
│       │   ├───java
│       │   └───resources
│       │       │   application.properties
│       │       │
│       │       └───db
│       │           └───changelog
│       │               │   db.changelog-master.xml
│       │               │
│       │               └───1.0
│       │                       db.changelog-1.0.xml
│       │                       metadata_create.sql
│       │                       metadata_insert_data.sql
│       │                       metadata_rollback.sql
│       │
│       └───test
│           └───java
├───editor
│   │   pom.xml
│   │
│   └───src
│       ├───main
│       │   ├───java
│       │   └───resources
│       │       │   application.properties
│       │       │
│       │       └───META-INF
│       │               spring.factories
│       │
│       └───test
│           ├───java
│           │   └───ru
│           │       └───test
│           │           └───editor
│           │               └───EditorControllerTest.java   
│           │
│           └───resources
│                   application.yml
│       
│
└───engine
    │   pom.xml
    │
    └───src
        ├───main
        │   ├───java
        │   └───resources
        │           application.yml
        │
        └───test
            ├───java
            └───resources

But, When I start tests in editor, for example (EditorControllerTest.java), I get error, that Liquibase not found:

Caused by: java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration)

But, I set spring.liquibase.change-log parameter in application.properties in database-structure module. Why it is ignored?

If I specify this option in the editor module, everything works. How to collect all of the logic work with the Liquibase in the same place in database-structure module?

Naashom answered 22/6, 2019 at 18:26 Comment(2)
Centralized config is helpful. Please take a look at hereMacrospore
here you can read all about property files and how to specify multiple ones. docs.spring.io/spring-boot/docs/current/reference/htmlsingle/…Disingenuous
E
2

But, I set spring.liquibase.change-log parameter in application.properties in database-structure module. Why it is ignored?

At runtime, as with any resources or classes, the first application.properties found on the classpath at the root (/) will be picked up the others will be ignored.

Element answered 22/6, 2019 at 18:33 Comment(0)
S
0

I've kept changelogs files in shared configuration: see Change working directory for gradle multi-module project

And then refer to them in every needed sub-modules: Applying Liquibase migrations for integration tests on a multi module gradle project

Sap answered 4/9, 2022 at 21:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.