【发布时间】: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 错误。缺少使用自定义<sql>标签,我认为您无能为力(当然报告错误) -
是的,我想我会试试以防万一..
-
所以这个bug似乎是在3.4.1中引入的;已提出liquibase.jira.com/browse/CORE-2677
标签: postgresql liquibase