Liquibase 多个变更日志执行
Liquibase multiple changelog execution
我正在使用 SpringLiquibase
进行 liquibase 配置,以下配置适用于单个更新日志文件(sql 格式)
@Configuration
@Slf4j
public class LiquibaseConfiguration {
@Inject
private DataSource dataSource;
@Bean
public SpringLiquibase liquibase() {
log.info("################## Entering into liquibase #################");
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(dataSource);
liquibase.setChangeLog("classpath:schema/update-schema-01.sql");
// Configure rest of liquibase here...
// ...
return liquibase;
}
}
在我的应用程序中,我可能需要 运行 more than one changelog
个文件,但我无法执行这样的操作,
我尝试按如下方式提供多个更新日志,
liquibase.setChangeLog("classpath:schema/update-schema-01.sql");
liquibase.setChangeLog("classpath:schema/update-schema-02.sql");
最后一个变更日志文件单独执行。
liquibase.setChangeLog("classpath:schema/*.sql");
获取错误 liquibase.exception.ChangeLogParseException: java.io.IOException: Found 2 files that match classpath:schema/*.sql
请建议一种在此处包含所有更改日志的方法。
可能的解决方案之一:您可以创建主变更日志,这将 includes 其他变更日志随您所愿。在 SpringLiquibase
对象中,您将只设置一个主要的 liquibase 更新日志。
例如,假设您有 2 个更新日志文件:one-changelog.xml
和 two-changelog.xml
并且您需要 运行 两者。我建议您再创建一个文件 main-changelog.xml
并在其中包含 one-changelog.xml
和 two-changelog.xml
文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
<include file="one.xml"/>
<include file="two.xml"/>
</databaseChangeLog>
并将 main-changelog.xml
文件设置为 SpringLiquibase
的更新日志。
因此,您将拥有 2 个单独的更新日志文件。
我正在使用 SpringLiquibase
进行 liquibase 配置,以下配置适用于单个更新日志文件(sql 格式)
@Configuration
@Slf4j
public class LiquibaseConfiguration {
@Inject
private DataSource dataSource;
@Bean
public SpringLiquibase liquibase() {
log.info("################## Entering into liquibase #################");
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setDataSource(dataSource);
liquibase.setChangeLog("classpath:schema/update-schema-01.sql");
// Configure rest of liquibase here...
// ...
return liquibase;
}
}
在我的应用程序中,我可能需要 运行 more than one changelog
个文件,但我无法执行这样的操作,
我尝试按如下方式提供多个更新日志,
liquibase.setChangeLog("classpath:schema/update-schema-01.sql");
liquibase.setChangeLog("classpath:schema/update-schema-02.sql");
最后一个变更日志文件单独执行。
liquibase.setChangeLog("classpath:schema/*.sql");
获取错误 liquibase.exception.ChangeLogParseException: java.io.IOException: Found 2 files that match classpath:schema/*.sql
请建议一种在此处包含所有更改日志的方法。
可能的解决方案之一:您可以创建主变更日志,这将 includes 其他变更日志随您所愿。在 SpringLiquibase
对象中,您将只设置一个主要的 liquibase 更新日志。
例如,假设您有 2 个更新日志文件:one-changelog.xml
和 two-changelog.xml
并且您需要 运行 两者。我建议您再创建一个文件 main-changelog.xml
并在其中包含 one-changelog.xml
和 two-changelog.xml
文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
<include file="one.xml"/>
<include file="two.xml"/>
</databaseChangeLog>
并将 main-changelog.xml
文件设置为 SpringLiquibase
的更新日志。
因此,您将拥有 2 个单独的更新日志文件。