Skip to content

Added support deleting UNIQUE partial indexes

Compare
Choose a tag to compare
@pvsaintpe pvsaintpe released this 06 Aug 19:57
· 60 commits to master since this release
Added support deleting UNIQUE partial indexes (#22)

Added support for deleting unique indexes with WHERE conditions.

By default, if the created unique index contains no conditions, PostgresSQL automatically creates a Constraint for it, for example:

CREATE UNIQUE INDEX CONCURRENTLY examples_new_col_idx ON examples (new_col);
ALTER TABLE examples
    ADD CONSTRAINT examples_unique_constraint USING INDEX examples_new_col_idx;
If the unique index contains WHERE conditions, then such a Constraint will not be created, because PostgreSQL doesn't
define a partial (ie conditional) UNIQUE constraint.

When trying to delete such a partial unique index, we get the error "Unique Constraint not found", so the standard command to remove $table->dropUnique() does not fit, the command $table->dropIndex() is suitable, but if pass the array there, then the index name will be generated as for a regular index with the suffix _index, instead of _unique, which we need.

And manually generating the index name is wrong.

This Merge Request solves these problems.