LiquiBase - 将更改log sql输出到2.0.5中的文件的任何方法? [英] LiquiBase -- Any way to output change log sql to a file in 2.0.5?

查看:191
本文介绍了LiquiBase - 将更改log sql输出到2.0.5中的文件的任何方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用 liquibase.integration.spring.SpringLiquibase bean

Currently I am integrating Liquibase with my spring application using liquibase.integration.spring.SpringLiquibase bean

将Liquibase与我的spring应用程序集成java doc,知道有一个属性 sqlOutputDir 到那个bean类,以便sql可以输出到外部文件是合理的。

From java doc, tt is plausible to know there is an property sqlOutputDir to that bean class so that the sql can output to external file.

但是,最新2.0.5中似乎不存在该功能。

However, the feature seems not exist in latest 2.0.5.

所以,问题是,当前的等价物是多少方法或函数将changeLog sql输出到外部文件,或者该功能是否已被完全删除?

So, the question is, what is the current equivalent method or function to output changeLog sql to external file, or the feature just have been totally removed forever?

请给出提示,谢谢很多。

Please give a hint, thanks a lot.

推荐答案

用于编写SQL输出的等效Java命令是: Liquibase #update(String,作家)。您可以通过继承 SpringLiquibase 并覆盖 afterPropertiesSet 来在Spring应用程序中调用此方法。例如:

The equivalent Java command for writing the SQL output is: Liquibase#update(String, Writer). You can invoke this method in your Spring app by subclassing SpringLiquibase and overriding afterPropertiesSet. For example:

@Bean
public SpringLiquibase liquibase() {
    SpringLiquibase liquibase = new SpringLiquibaseWriter();
    // ...
    return liquibase;
}

private static class SpringLiquibaseWriter extends SpringLiquibase {

    @Override
    public void afterPropertiesSet() throws LiquibaseException {

        try (Connection connection = getDataSource().getConnection()) {

            Liquibase liquibase = createLiquibase(connection);
            Writer writer; // ... get writer
            liquibase.update(getContexts(), writer);
            // ...

        } catch (LiquibaseException | SQLException e) {
            // handle
        }

        super.afterPropertiesSet();
    }
}

更新的调用( String,Writer)将执行您的更改集而不实际更新数据库。对 super.afterPropertiesSet 的调用将实际执行liquibase更新。

The call to update(String,Writer) will execute your changesets without actually updating the database. The call to super.afterPropertiesSet will actually perform the liquibase updates.

我注意到 SpringLiquibase 中提到的http://www.liquibase.org/api/liquibase/spring/SpringLiquibase.html\"rel =noreferrer> javadoc 提到 writeSqlFileEnabled sqlOutputDir 属性。显然,这些已被删除,但javadoc未更新(请参阅 CORE-1104 )。我不确定这些选项被删除的原因或预期的替代品是什么。我发现liquibase日志记录有点不足,所以这种方法对于记录(调试)liquibase SQL输出可能很有用。

I did notice the javadoc you referred to in SpringLiquibase that mentions the writeSqlFileEnabled and sqlOutputDir properties. Apparently, these were removed but the javadoc was not updated (see CORE-1104). I'm not sure the reason that these options were removed or what the intended replacements are though. I've found that liquibase logging is a bit deficient, so this approach may be useful for logging (debugging) the liquibase SQL output.

这篇关于LiquiBase - 将更改log sql输出到2.0.5中的文件的任何方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆