本文介绍了当调用updateSQL时,CustomTaskChange会实际执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Liquibase中有一个 CustomTaskChange (除了其他ChangeSet).我希望我的应用程序在实际执行之前显示所有ChangeSet的SQL.以我的理解, updateSQL 应该预览SQL并且不执行任何操作.但是,会立即执行 CustomTaskChange .我希望在调用 updateSQL 时会忽略 CustomTaskChange .

I have a CustomTaskChange in Liquibase (besides other ChangeSets). I want my application to show the SQL of all ChangeSets before actually executing it. In my understanding, updateSQL should preview the SQL and execute nothing. A CustomTaskChange however gets executed right away. I would have expected that the CustomTaskChange is ignored, when calling updateSQL.

ChangeSet:

The ChangeSet:

<changeSet id="2" author="clu">
    <comment>Print out 'helloworld'.</comment>
    <customChange class="path.to.HelloWorldUpdate">
</customChange>
</changeSet>

CustomTaskChange:

The CustomTaskChange:

public class HelloWorldUpdate implements CustomTaskChange {
    @Override
public void execute(Database database) throws CustomChangeException {
    System.out.println("HELLO WORLD!!");
}
}

调用 updateSQL 时,控制台将显示"HELLO WORLD !!"

When calling updateSQL the console prints "HELLO WORLD!!"

这是一个错误吗?有解决方法吗?

Is this a bug? Is there a workaround?

谢谢!

[已编辑]

推荐答案

CustomTaskChange 说:

Interface to implement when creating a custom change that does not actually
generate SQL. If you are updating a database through SQL, 
implementing CustomSqlChange is preferred because the SQL can either 
be executed directly or saved to a text file for later use depending 
on the migration mode used.

因此,请使用 CustomSqlChange 代替.

So use a CustomSqlChange instead.

generateStatements()方法中,您还可以在返回 SqlStatement [] 数组之前打印出sql.println将每次运行.但是,您创建的语句将不会应用于数据库,而只会在您选择使用 updateSQL 运行它时打印出来以显示出来.

In the generateStatements() method you can also print out your sql before you return your SqlStatement[] array. The println will run every time. But the statements you created will not be applied to the database but instead just be printed to std out when you choose to run it with updateSQL.

这篇关于当调用updateSQL时,CustomTaskChange会实际执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 20:59