【问题标题】:Problems dropping an index in postgres using liquibase使用 liquibase 在 postgres 中删除索引的问题
【发布时间】:2016-02-24 13:09:46
【问题描述】:

我在 liquibase 中遇到了一个问题,我无法在我的 postgres 数据库中删除索引。 liquibase报的错误是

Unexpected error running Liquibase: ERROR: index "value_idx" does not exist [Failed SQL: DROP INDEX VALUE_IDX]

我已经使用 psql 连接到数据库并验证了索引确实存在(如果变更集在没有 drop index 节的情况下运行)

\d data
          Table "someschema.data"
 Column |         Type          | Modifiers
--------+-----------------------+-----------
 value  | character varying(36) | not null
Indexes:
    "value_idx" UNIQUE, btree (value)

运行 Liquibase updateSQL 时,它生成的DROP INDEX 语句是:

DROP INDEX VALUE_IDX;

我的更新日志如下:

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

    <preConditions>
        <dbms type="postgresql"/>
    </preConditions>

    <changeSet author="beresfordt" id="1">

        <sql>
            CREATE SCHEMA SomeSchema;
        </sql>

        <createTable tableName="data" schemaName="someschema">
            <column name="value" type="varchar(36)">
                <constraints nullable="false"/>
            </column>
        </createTable>

        <createIndex indexName="VALUE_IDX" schemaName="someschema"
                     tableName="data" unique="true">
            <column name="value" type="varchar(36)"/>
        </createIndex>

        <dropIndex catalogName="someschema"
                schemaName="someschema"
                tableName="data"
                indexName="VALUE_IDX"/>
    </changeSet>
</databaseChangeLog>

我还尝试了以下 dropindex 节:

        <dropIndex catalogName="someschema"
                schemaName="someschema"
                tableName="data"
                indexName="someschema.VALUE_IDX"/>

但我得到一个类似的错误:

Unexpected error running Liquibase: ERROR: index "someschema.VALUE_IDX" does not exist [Failed SQL: DROP INDEX "someschema.VALUE_IDX"]

我正在使用 Liquibase:3.4.2 和 Postgres:9.5.1

编辑:

在 3.3.0 上尝试过,它可以工作。

liquibase 的 jira 中出现的错误:https://liquibase.jira.com/browse/CORE-2677

【问题讨论】:

  • 由于表存储在架构someschema 中,因此索引也需要使用架构进行限定(除非someschema 位于用户的search_path 中)。因此,如果我没记错的话,它必须是 drop index someschema.value_idx; - 这似乎是 Liquibase 中的一个错误
  • 我尝试将模式显式放在 dropIndex 节的 indexName 属性中,但它也不喜欢那样。将更新问题
  • 您已经在 schemaName 属性中指定了架构。如果将架构​​名称放入索引名称中,Liquibase 会假定索引名为 "someschema.VALUE_IDX",这与 "someschema"."value_idx" 不同。正如我所说:我确实认为这是一个 Liquibase 错误。缺少使用自定义 &lt;sql&gt; 标签,我认为您无能为力(当然报告错误)
  • 是的,我想我会试试以防万一..
  • 所以这个bug似乎是在3.4.1中引入的;已提出liquibase.jira.com/browse/CORE-2677

标签: postgresql liquibase


【解决方案1】:

这是由在编写 Liquibase 3.4.1 和 3.4.2 时存在的错误引起的。

这已在 Liquibase jira 上提出:https://liquibase.jira.com/browse/CORE-2677

编辑:

这似乎已经在当前头部解决了:'03b020ab895eb02c0e0aba90461cb7c628fa033f'

编辑 2:

从 Liquibase 更新:

修复应该在 3.5 中发布

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 2011-06-27
    • 2021-12-16
    • 1970-01-01
    • 2018-12-20
    • 2016-03-04
    • 1970-01-01
    相关资源
    最近更新 更多