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

[10.x] Add hasIndex and hasIndexes methods to Schema Builder #49260

Closed
wants to merge 6 commits into from

Conversation

liamkeily
Copy link
Contributor

@liamkeily liamkeily commented Dec 6, 2023

This PR introduces two new methods to the Schema builder: Schema::hasIndex($table, $index) and Schema::hasIndexes($table, $indexes). These methods align with the existing hasColumn and hasColumns methods as discussed on #49204 (comment)

Usage

Schema::hasIndex('user', 'email');

Schema::hasIndexes('user', ['email', 'name']);

Testing

Added unit tests, but also tested manually to ensure it actually works with real database

image

@liamkeily liamkeily marked this pull request as ready for review December 6, 2023 11:38
@liamkeily liamkeily marked this pull request as draft December 6, 2023 11:43
@liamkeily liamkeily marked this pull request as ready for review December 6, 2023 12:02
@liamkeily liamkeily marked this pull request as draft December 6, 2023 12:04
@liamkeily liamkeily changed the title Add Schema::hasIndex method Add hasIndex and hasIndexes Methods to Schema Builder Dec 6, 2023
@liamkeily liamkeily marked this pull request as ready for review December 6, 2023 12:17
@crynobone crynobone changed the title Add hasIndex and hasIndexes Methods to Schema Builder [10.x] Add hasIndex and hasIndexes methods to Schema Builder Dec 6, 2023
@morloderex
Copy link
Contributor

@liamkeily This doesn't generate the index using the traditional naming conventions for indexes.

See the createIndexName method on the Illuminate\Database\Schema\Blueprint class.

Also we should probably allow specifying a type of index in order for this to work probably.

@taylorotwell
Copy link
Member

Will let @hafezdivandari handle these methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants