The method Schema::indexExists() does not work for unique indexes in PostgreSQL

Created on 5 December 2022, over 1 year ago
Updated 30 October 2023, 7 months ago

Problem/Motivation

Unique indexes that have been created with the method Schema::addUniqueKey() should be able to test with the method Schema::indexExists() in PostgreSQL.

Steps to reproduce

Create an unique index with the method Schema::addUniqueKey() and than test its existance with the method Schema::indexExists(). The call should return TRUE, only it is returning FALSE.

Proposed resolution

Fix the method

Remaining tasks

Create fix and test.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
PostgreSQL driverΒ  β†’

Last updated 10 days ago

No maintainer
Created by

πŸ‡³πŸ‡±Netherlands daffie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΈπŸ‡°Slovakia poker10

    Indexes are created via Schema::addIndex() and have suffix __idx. The Schema::indexExists() checks only for indexes created via Schema::addIndex() (and it checks pg_indexes).

    Unique keys are created as constraints via Schema::addUniqueKey() and have suffix __key. There is a Schema::constraintExists() which checks for PK, FK, UK (and it checks pg_constraint).

    It is true, that pg_indexes contains records for PK, UK, .., but I am not sure (when using our terminology - index vs unique key) if the Schema::indexExists() should check for unique keys. Now it is separated in two functions - one for indexes, one for constraints. Otherwise would not be the Schema::constraintExists() redundant?

    From older PostgreSQL docs - https://www.postgresql.org/docs/9.4/indexes-unique.html:

    The use of indexes to enforce unique constraints could be considered an implementation detail that should not be accessed directly.

    We are creating UK as constraints and despite the fact that there is an index created in the background, should not we treat them as constraints?

    Is there a reason why the current behavior is a bug and what problems is this behavior causing (would be great to update IS with these information)? Thanks!

Production build 0.69.0 2024