[英]Liquibase doesn't load *.sql from classpath inside of changeSet
I need configure changeSet executing sql loaded from jar.我需要配置 changeSet 执行从 jar 加载的 sql。
I have internal project changeSet
that works correctly我有可以正常工作的内部项目
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>
Some scripts are provided from different libraries (in my case it is spring-boot-starter-batch
), for example:一些脚本是从不同的库中提供的(在我的例子中是
spring-boot-starter-batch
),例如:
classpath:/org/springframework/batch/core/schema-h2.sql
Note that jar is in the project and accessible (build \\ test\\ run times).请注意,jar 在项目中并且可以访问(构建\\测试\\运行时)。 As result I need register one also into my
changeSet
, trying:因此,我还需要在我的
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>
and it doesn't work with any configuration (like "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"
and so on) because of它不适用于任何配置(如
"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'
I know using spring I could use auto configuration, but I'm interested in liquibase auditing...我知道使用 spring 我可以使用自动配置,但我对 liquibase 审计感兴趣......
Is any ideas how to make packaged scripts working via changeSet
or include into liquibase auditing?任何想法如何使包装脚本通过工作
changeSet
或包括到liquibase审计?
Solution is to change attribute for sqlFile
tag:解决方案是更改
sqlFile
标记的属性:
relativeToChangelogFile="false"
Result changeSet
below:结果
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>
Example for separate changelog.yaml file with relative path:具有相对路径的单独 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.