Reputation: 7543
I need configure changeSet executing sql loaded from jar.
I have internal project changeSet
that works correctly
<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:
classpath:/org/springframework/batch/core/schema-h2.sql
Note that jar is in the project and accessible (build \ test\ run times).
As result I need register one also into my changeSet
, trying:
<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
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...
Is any ideas how to make packaged scripts working via changeSet
or include into liquibase auditing?
Upvotes: 4
Views: 5797
Reputation: 19880
Example for separate changelog.yaml file with relative path:
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
Upvotes: 1
Reputation: 7543
Solution is to change attribute for sqlFile
tag:
relativeToChangelogFile="false"
Result changeSet
below:
<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>
Upvotes: 5