【问题标题】:Liquibase multiple changelog executionLiquibase 多个变更日志执行
【发布时间】:2019-05-24 21:34:01
【问题描述】:

我正在使用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

请在此处提出一种包含所有变更日志的方法。

【问题讨论】:

    标签: java spring liquibase


    【解决方案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 个单独的变更日志文件。

    【讨论】:

    • 您的意思是将所有其他更改日志内容放在一个日志中并使用它?
    • 这是一个很好的建议,我的情况是使用 sql 格式的变更日志,我想我可以将主变更日志作为 xml 并在 sql 中包含变更日志。我会试试的。
    • 可以,同样的方式可以包含sql文件
    • 它的工作原理是在 main-changelog.xml 中包含 &lt;includeAll path="schema/"/&gt;,非常感谢 :-)
    猜你喜欢
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2021-09-02
    • 2021-01-18
    相关资源
    最近更新 更多