Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support deleting UNIQUE partial indexes #22

Merged
merged 4 commits into from
Aug 6, 2019

Conversation

pvsaintpe
Copy link
Member

@pvsaintpe pvsaintpe commented Aug 5, 2019

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.

@pvsaintpe pvsaintpe added bug Something isn't working feature New Features labels Aug 5, 2019
@pvsaintpe pvsaintpe added this to the 2.5.1 milestone Aug 5, 2019
@pvsaintpe pvsaintpe requested a review from lazeevv August 5, 2019 17:25
@pvsaintpe pvsaintpe self-assigned this Aug 5, 2019
@pvsaintpe pvsaintpe requested review from cugrif and Zlob August 5, 2019 17:27
@pvsaintpe pvsaintpe changed the title Added supporting delete unique partial indexes Added support deleting UNIQUE partial indexes Aug 6, 2019
README.md Outdated Show resolved Hide resolved
@lazeevv lazeevv merged commit 7e5312a into master Aug 6, 2019
@pvsaintpe pvsaintpe deleted the bugs/unique-constraints branch December 20, 2020 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants