Skip to content

[12.x] Add support for PostgreSQL "unique nulls not distinct" #55025

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

Merged

Conversation

thierry2015
Copy link
Contributor

@thierry2015 thierry2015 commented Mar 14, 2025

What

This adds support for PostgreSQL (>= 15) unique nulls [not] distinct when building unique indexes.

Why

The only way to execute such a statement inside a migration at the moment is to wait after the table creation (outside the Schema::create() statement, as AFAIK there's no way to inform the blueprint of a custom command to be executed) or by extending the Postgres schema grammar (idea thread)

How

By adding support for a new nullsNotDistinct() fluent index definition method (see the unit tests for some examples) when using the postgres database driver (or more precisely when using the Postgres schema grammar).

Benefits

Developers will now be able to use this native PostgreSQL feature, which could reduce the scope of work when building a feature requiring unique database record combinations, including null values.

@thierry2015 thierry2015 changed the title Add support for PostgreSQL "unique nulls not distinct" [12.x] Add support for PostgreSQL "unique nulls not distinct" Mar 14, 2025
@taylorotwell taylorotwell merged commit 2416981 into laravel:12.x Mar 16, 2025
41 checks passed
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.

2 participants