Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of relativeToChangelogFile with classpath: prefixed changelogs #2189

Merged
merged 2 commits into from Nov 22, 2021

Conversation

nvoxland
Copy link
Contributor

@nvoxland nvoxland commented Nov 5, 2021

Description

This is Windows specific issue.

In 4.6.0, a change broke the ability for spring boot projects that reference their changelog files with a classpath: prefix to include files with relativeToChangelog=true

Replication Info

pom.xml file (liquibase dependency):

<dependency>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-core</artifactId>
    <version>4.6.0</version>
</dependency>

application.yml file:

spring:
  liquibase:
    change-log: classpath:/db/changelog/db-changelog.yml
  dataSource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: "jdbc:mysql://localhost:3306/intuser_db?serverTimezone=UTC"
    username: root
    password: password

db-changelog.xml file:

databaseChangeLog:
  - include:
      relativeToChangelogFile: true
      file: 001-users.yml
  - include:
      relativeToChangelogFile: true
      file: 002-chats.yml
These files come from https://github.com/nsobadzhiev/liquibase-cascade-demo which also replicates the issue.
Error Message
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-11-11 09:55:43.425 ERROR 11908 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Error parsing classpath:/db/changelog/db-changelog.yml

Work Around

Removing classpath: from your changelog file configuration will avoid the bug.


Dev Handoff Notes (Internal Use)

Links

Testing

  • Steps to Reproduce: "See above"
  • Guidance:
    • Impact: Only fixes up times when people have classpath: as a prefix in their changelog setting for includes

Dev Verification

I found the bug when testing a different problem using the referenced repo. Running mvn test reproduced the problem. After the fix, mvn test worked.

I didn't include a unit test for the change because it's in a part of the code that would need a good amount of setup to be able to test. We need to get tests written around the spring integration better, and those tests will catch this at that point.

Test Requirements (Liquibase Internal QA)

SpringBoot includes a built-in version of Liquibase which is quite old. Newer builds of Liquibase break handling of the Liquibase classpath. To reproduce this bug, specify an exact Liquibase version in the pom.xml. (See pom.xml example in repro steps for how to specify Liquibase 4.6.0).

Testing requires one MySQL database instance.

Manual Tests

Setup:

  • Git clone the https://github.com/nsobadzhiev/liquibase-cascade-demo repository.
  • Update the pom.xml file in liquibase-cascade-demo to specify the Liquibase fix branch as the version for the Liquibase dependency.
    • 	<dependency>
      		<groupId>org.liquibase</groupId>
      		<artifactId>liquibase-core</artifactId>
      		<version>4.6.1-fix-classpath-prefix-include</version>
      	</dependency>
      


* Update the application.yml file in liquibase-cascade-demo\main\resources to have the correct url, username and password for your local MySQL instance.
* In the liquibase-cascade-demo directory, execute a Maven compile.
  * This gets all the necessary dependencies to build the application jar.
  * `mvn compile`
* In the liquibase-cascade-demo directory, execute a Maven package without running tests.
  * This builds the application jar file (demo-0.0.1-SNAPSHOT.jar).
  * If the tests are not skipped, Liquibase will automatically run during packaging. We are going to test the fix by running the application itself instead of during mvn package.
  * The application jar is created in liquibase-cascade-demo/target
  * `mvn package -DskipTests`

_Verify the SpringBoot appliation does not fail due to an error loading the Liquibase classpath._

* CD to liquibase-cascade-demo/target
* Run the application: `java -jar demo-0.0.1-SNAPSHOT.jar`
  * There is no error message about failure to load the Liquibase classpath.
  * The output to console shows Liquibase create table account
  * The output to console shows Liquibase create table chat

_Verify the SpringBoot application successful created objects on the database._

* The table account exists.
* The table chat exists.

**Automated Tests**

* None required for this fix.



┆Issue is synchronized with this [Jira Bug](https://datical.atlassian.net/browse/LB-2158) by [Unito](https://www.unito.io)

@nvoxland nvoxland added this to To Do in Conditioning++ via automation Nov 5, 2021
@nvoxland nvoxland moved this from To Do to Code Review in Conditioning++ Nov 5, 2021
@suryaaki2 suryaaki2 self-requested a review November 8, 2021 19:03
@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Nov 8, 2021
@sync-by-unito
Copy link

sync-by-unito bot commented Nov 18, 2021

➤ Erzsebet Carmean commented:

Liquibase 4.6.1-fix-classpath-prefix-include-SNAPSHOT #2Testing done with MySQL 8 on a Windows 10 OS.

  • Issue never existed on Linux OS. This was tested and verified by another Liquibase internal QA.

Verify the SpringBoot application does not fail due to an error loading the Liquibase classpath. PASS

  • There is no error message about failure to load the Liquibase classpath. PASS
  • The output to console shows Liquibase create table account PASS
  • The output to console shows Liquibase create table chat PASS

Verify the SpringBoot application successfully created objects on the database. PASS

  • The table account exists. PASS
  • The table chat exists. PASS

Output of Fixed BuildC:\Users\erz\work\liquibase-cascade-demo\target>java -jar demo-0.0.1-SNAPSHOT.jar

. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
' |
| .__|| ||| |_, | / / / /
=========|
|==============|/=////
:: Spring Boot :: (v2.5.3)

2021-11-18 12:14:28.258 INFO 20420 --- [ main] c.e.demo.LiquibaseDemoApplicationKt : Starting LiquibaseDemoApplicationKt v0.0.1-SNAPSHOT using Java 14.0.2 on LENOVO with PID 20420 (C:\Users\erz\work\liquibase-cascade-demo\target\demo-0.0.1-SNAPSHOT.jar started by erz in C:\Users\erz\work\liquibase-cascade-demo\target)
2021-11-18 12:14:28.274 INFO 20420 --- [ main] c.e.demo.LiquibaseDemoApplicationKt : No active profile set, falling back to default profiles: default
2021-11-18 12:14:28.907 INFO 20420 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-11-18 12:14:28.922 INFO 20420 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 3 ms. Found 0 JPA repository interfaces.
2021-11-18 12:14:29.461 INFO 20420 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-11-18 12:14:29.817 INFO 20420 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-11-18 12:14:30.181 INFO 20420 --- [ main] liquibase.lockservice : Successfully acquired change log lock
2021-11-18 12:14:30.367 INFO 20420 --- [ main] liquibase.changelog : Creating database history table with name: testdb1.DATABASECHANGELOG
2021-11-18 12:14:30.411 INFO 20420 --- [ main] liquibase.changelog : Reading from testdb1.DATABASECHANGELOG
2021-11-18 12:14:30.499 INFO 20420 --- [ main] liquibase.changelog : Table account created
2021-11-18 12:14:30.501 INFO 20420 --- [ main] liquibase.changelog : ChangeSet /db/changelog/001-users.yml::1::nikola ran successfully in 39ms
2021-11-18 12:14:30.566 INFO 20420 --- [ main] liquibase.changelog : Table chat created
2021-11-18 12:14:30.622 INFO 20420 --- [ main] liquibase.changelog : Table test_table created
2021-11-18 12:14:30.624 INFO 20420 --- [ main] liquibase.changelog : ChangeSet /db/changelog/002-chats.yml::1::nikola ran successfully in 109ms
2021-11-18 12:14:30.644 INFO 20420 --- [ main] liquibase.lockservice : Successfully released change log lock
2021-11-18 12:14:30.778 INFO 20420 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-11-18 12:14:30.825 INFO 20420 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
2021-11-18 12:14:30.979 INFO 20420 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-11-18 12:14:31.105 INFO 20420 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2021-11-18 12:14:31.264 INFO 20420 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-11-18 12:14:31.279 INFO 20420 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-11-18 12:14:31.364 INFO 20420 --- [ main] c.e.demo.LiquibaseDemoApplicationKt : Started LiquibaseDemoApplicationKt in 3.634 seconds (JVM running for 4.091)
2021-11-18 12:14:31.364 INFO 20420 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-11-18 12:14:31.364 INFO 20420 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2021-11-18 12:14:31.388 INFO 20420 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.Everything looks good here. Moving to ready to merge.

@suryaaki2 suryaaki2 merged commit 6dc3abe into master Nov 22, 2021
Conditioning++ automation moved this from Ready for Handoff (In JIRA) to Done Nov 22, 2021
@suryaaki2 suryaaki2 deleted the fix-classpath-prefix-include branch November 22, 2021 23:00
@nvoxland nvoxland removed this from Done in Conditioning++ Dec 1, 2021
@nvoxland nvoxland added this to the v4.6.2 milestone Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants