[英]Liquibase doesn't load *.sql from classpath inside of changeSet
我需要配置 changeSet 执行从 jar 加载的 sql。
我有可以正常工作的内部项目changeSet
集
<changeSet id="1" author="sergii" dbms="h2">
<sqlFile
encoding="utf8"
path="schema-ms-sql.0.0.1.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>
一些脚本是从不同的库中提供的(在我的例子中是spring-boot-starter-batch
),例如:
classpath:/org/springframework/batch/core/schema-h2.sql
请注意,jar 在项目中并且可以访问(构建\\测试\\运行时)。 因此,我还需要在我的changeSet
注册一个,尝试:
<changeSet id="2" author="sergii" dbms="h2">
<sqlFile
encoding="utf8"
path="classpath*:/org/springframework/batch/core/schema-h2.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>
它不适用于任何配置(如"classpath:/org/springframework/batch/core/schema-h2.sql"
、 "/org/springframework/batch/core/schema-h2.sql"
、 "org/springframework/batch/core/schema-h2.sql"
, "classpath*:/org/springframework/batch/core/schema-h2.sql"
等等)因为
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.UnexpectedLiquibaseException: java.io.IOException: File does not exist: 'classpath*:/org/springframework/batch/core/schema-h2.sql'
我知道使用 spring 我可以使用自动配置,但我对 liquibase 审计感兴趣......
任何想法如何使包装脚本通过工作changeSet
或包括到liquibase审计?
解决方案是更改sqlFile
标记的属性:
relativeToChangelogFile="false"
结果changeSet
如下:
<changeSet id="2" author="sergii" dbms="h2">
<sqlFile
encoding="utf8"
path="classpath:/org/springframework/batch/core/schema-h2.sql"
relativeToChangelogFile="false"
splitStatements="true"
stripComments="true"/>
</changeSet>
具有相对路径的单独 changelog.yaml 文件的示例:
databaseChangeLog:
- changeSet:
id: my_script_1
changes:
- sqlFile:
dbms: mysql
encoding: utf8
path: db/changelog/0_0_1/my_script_1.sql
relativeToChangelogFile: false
splitStatements: true
stripComments: true
rollback:
- sqlFile:
dbms: mysql
encoding: utf8
path: db/changelog/0_0_1/my_script_1_rollback.sql
relativeToChangelogFile: false
splitStatements: true
stripComments: true
- changeSet:
id: my_script_2
changes:
- sqlFile:
dbms: mysql
encoding: utf8
path: db/changelog/0_0_1/my_script_2.sql
relativeToChangelogFile: false
splitStatements: true
stripComments: true
rollback:
- sqlFile:
dbms: mysql
encoding: utf8
path: db/changelog/0_0_1/my_script_2_rollback.sql
relativeToChangelogFile: false
splitStatements: true
stripComments: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.