liquibase更新后的其他“ GO”

时间:2018-09-12 11:07:10

标签: sql-server liquibase

在更新到liquibase 3.6.1之后,如果旧的<sql>更改集使用了DECLARE变量,则它们会损坏。

显然现在在空行的地方添加了其他GO语句,这不是它过去的工作方式,它现在使我们的旧文件抛出 liquibase.exception.DatabaseException: Must declare the scalar variable "@foo"

我们该如何解决这个问题或修复较旧的文件以在旧数据库副本上工作而又不会在最新的副本上运行?

1 个答案:

答案 0 :(得分:1)

The scope of T-SQL Variables is at the T-SQL batch. Batch is completed with the "GO" command. Therefore, after GO, @foo would have to be re-declared.

For example:

DECLARE @foo int = 0;

GO

SELECT @foo; -- This line will give an error.

If the GO is moved to the end, then it will work, and return the value of @foo.

DECLARE @foo int = 1;

SELECT @foo; -- This line will return 1.

GO

Batch Scope is not a new behavior of SQL Server, it's been the behavior since version 1.

Try looking at LiquidBase's 'sqlFile' tag, and see if the endDelimiter attribute or splitStatements attribute have been set incorrectly.