如果表存在则跳过 liquibase 更改

liquibase 的新手。我有一个由休眠管理的现有架构。我现在需要删除一些表,我正在使用 liquibase。我写了一个成功删除表的配置。


但我希望检查仅在表存在时运行,因为新安装的系统不会有表,因为休眠映射对象不再存在。


我试图添加一个先决条件。但是,我的日志仍然表明 liquibase 失败,因为它试图删除该表但它不存在。我做错了什么?我正在使用 Spring Boot / Java


databaseChangeLog:

  - preConditions:

      on-fail: mark_ran

      on-error: mark_ran

      tableExists:

        tableName: some_old_table

        schemaName: public

  - changeSet:

      id: 01_del_old_table

      author: some-dev-01

      comment: Remove old table

      changes:

        - dropTable:

            tableName: some_old_table

日志中的错误:表 public.some_old_table 不存在 ...


PreconditionFailedException

这就像 ti 正在检查先决条件……但仍然没有通过。


也试过


databaseChangeLog:

  - changeSet:

      id: zzchange-1.0-remove-xczczxc

      author: zzzz

      comment: Remove some_old_table table - no longer needed

      preConditions:

        on-fail: mark_ran

        tableExists:

          tableName: some_old_table

      changes:

        - dropTable:

            tableName: some_old_table


GCT1015
浏览 392回答 3
3回答

收到一只叮咚

问题在于on-fail属性拼写不正确。on-fail应该是onFail。最好将先决条件置于特定更改集的范围内,并且注释应该在先决条件之后进行,尽管这不是这里的问题。databaseChangeLog:  - changeSet:      id: zzchange-1.0-remove-xczczxc      author: zzzz      preConditions:        onFail: mark_ran        tableExists:          tableName: some_old_table      comment: Remove some_old_table table - no longer needed      changes:        - dropTable:            tableName: some_old_table

心有法竹

在你的第二次尝试中,在你的先决条件之后发表你的评论databaseChangeLog:  - changeSet:      id: zzchange-1.0-remove-xczczxc      author: zzzz      preConditions:        on-fail: mark_ran        tableExists:          tableName: some_old_table      comment: Remove some_old_table table - no longer needed      changes:        - dropTable:            tableName: some_old_table我不太确定为什么您的第一次尝试行不通,但是我认为拥有全局先决条件不是一个好主意。这是因为他们在同一文档中所说的:Preconditions at the changelog level apply to all changesets, not just those listed in the current changelog or its child changelogs.

哔哔one

请使用以下语法跳过当前表中的更改CREATE table IF NOT EXISTS
打开App,查看更多内容
随时随地看视频慕课网APP