Liquibase:通过“更新”和“删除”更改类型验证受影响的行数

问题描述 投票:0回答:1

在 Liquibase 中,

update
delete
更改类型使用
where
查询来定位多行。

有没有办法强制这两种更改类型影响的行数?

类似以下内容:

update:
  tableName: MY_TABLE
  columns:
  - column: {name: col1, value: col1_value}
  where: col2 = 'col2_value'
  expectedResult: 2

preConditions
不是一个合适的解决方案,因为:

  • 相应的查询与更改类型的查询分开维护和执行
  • changes
    可以包含许多
    update
    /
    delete
    查询
liquibase
1个回答
0
投票

您可以为此使用 sqlCheck 前提条件。

只需复制更新/删除变更集的条件并检查预期的行数。

我对 yaml 表示法不太熟悉,但它看起来像这样:

changeSet:
     id:  foo
     author: bar
     preConditions:
       - onFail: MARK_RAN
       - sqlCheck:
          expectedResult: 2
          sql: SELECT COUNT(*) FROM MY_TABLE WHERE col2 = 'col2_value'
     changes:
     - update:
        tableName: MY_TABLE
        columns:
        - column: {name: col1, value: col1_value}
        where: col2 = 'col2_value'
© www.soinside.com 2019 - 2024. All rights reserved.