Liquibase : link main yaml changelog from test

家住魔仙堡 提交于 2019-12-11 04:21:12

问题


I want to link yaml database creation rules from src/main/resources.. in src/test/resources and add one more chagngelog with sample data.

src\test\resources\db\changelog\db.changelog-master.yaml :

databaseChangeLog:
- include:
    file: ../../main/resources/db/changelog/db.changelog-master.yaml
- include:
    file: db/changelog/marketplace/sampleData.yaml

But it doesn't work. So, the error is : Error parsing ../../main/resources/db/changelog/db.changelog-master.yaml

Is there any other options to link main resources from main? This is a spring boot project.

Error stack trace :

Caused by: liquibase.exception.ChangeLogParseException: Error parsing classpath:/db/changelog/db.changelog-master.yaml
at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:84)
at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:217)
at liquibase.Liquibase.update(Liquibase.java:190)
at liquibase.Liquibase.update(Liquibase.java:179)
at 

...

Caused by: java.io.FileNotFoundException: class path resource [../../main/resources/db/changelog/db.changelog-master.yaml] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195)
at liquibase.integration.spring.SpringLiquibase$SpringResourceOpener.getResourcesAsStream(SpringLiquibase.java:504)
at liquibase.util.StreamUtil.singleInputStream(StreamUtil.java:186)
at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:27)
... 52 more

回答1:


I would suggest to name changelog file located in test path differently, because during test, main/test paths are merged into one relative path for the test suite run. I suspect Liquibase thinks that you are trying to include same file recursively.

Just rename your db.changelog-master.yaml under test path to db.changelog-master-test.yaml




回答2:


We include SQL files this way:

  - sqlFile:
      encoding: utf8
      path: /db/changelog/schema/schema.sql

So try to add slash at the beginning.




回答3:


Give the full path instead of ../../main/resources/db/changelog/db.changelog-master.yaml compiler is not able to parse the path in .. format.

Below is enough to load file if the file is present in classpath otherwise give full project context path.

db/changelog/db.changelog-master.yaml


来源:https://stackoverflow.com/questions/53337527/liquibase-link-main-yaml-changelog-from-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!