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

Add NULLS NOT DISTINCT #6054

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

langovoi
Copy link

@langovoi langovoi commented Apr 6, 2024

Postgres 15+ allows to add NULLS NOT DISTINCT for unique indexes and constraints.

I added nullNotDistinct: boolean option for unique in TableBuilder, to make possible to use this feature.

https://www.postgresql.org/about/featurematrix/detail/392/

@coveralls
Copy link

Coverage Status

coverage: 92.852% (+0.01%) from 92.842%
when pulling 80045e1 on langovoi:add-nulls-not-distinct
into aedba5e on knex:master.

@rluvaton
Copy link
Member

rluvaton commented Apr 6, 2024

Thank you for the PR, please throw an error for other dialects when they try to use it

@langovoi
Copy link
Author

langovoi commented Apr 6, 2024

Done! @rluvaton is it look well?

Copy link
Member

@rluvaton rluvaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for the other dialects that they are throwing and integration test for postgres that it actually works

({ indexName, deferrable, predicate } = indexName);
({ indexName, deferrable, predicate, nullsNotDistinct } = indexName);
}
if (nullsNotDistinct !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow null as well

Suggested change
if (nullsNotDistinct !== undefined) {
if (nullsNotDistinct != null) {

({ indexName, deferrable } = indexName);
({ indexName, deferrable, nullsNotDistinct } = indexName);
}
if (nullsNotDistinct !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow null as well

Suggested change
if (nullsNotDistinct !== undefined) {
if (nullsNotDistinct != null) {

}
if (deferrable && deferrable !== 'not deferrable') {
this.client.logger.warn(
`mysql: unique index \`${indexName}\` will not be deferrable ${deferrable} because mysql does not support deferred constraints.`
);
}
if (nullsNotDistinct !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow null as well

Suggested change
if (nullsNotDistinct !== undefined) {
if (nullsNotDistinct != null) {

@@ -298,6 +300,9 @@ class TableCompiler_MSSQL extends TableCompiler {
if (useConstraint && predicate) {
throw new Error('mssql cannot create constraint with predicate');
}
if (nullsNotDistinct !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow null as well

Suggested change
if (nullsNotDistinct !== undefined) {
if (nullsNotDistinct != null) {

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.

None yet

3 participants