Liquibase多个变更日志执行

时间:2019-05-24 12:15:16

标签: java spring liquibase

我正在使用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的身份获取错误

请在此处建议一种包括所有变更日志的方法。

1 个答案:

答案 0 :(得分:1)

可能的解决方案之一:您可以创建主变更日志,该日志将includes尽可能多地添加其他变更日志。在SpringLiquibase对象中,您将只设置一个主liquibase更改日志。

例如,假设您有2个变更日志文件:one-changelog.xmltwo-changelog.xml,则需要同时运行这两个文件。建议您再创建一个文件main-changelog.xml,并在文件one-changelog.xmltwo-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个单独的变更日志文件。

相关问题