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

Partial Unique Indexes should not be marked as is_unique #543

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sql/load_sql_context.sql
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ select
),
array[]::text[]
),
'is_unique', pi.indisunique,
'is_unique', pi.indisunique and pi.indpred is null,
'is_primary_key', pi.indisprimary
)
)
Expand Down
116 changes: 116 additions & 0 deletions test/expected/issue_542_partial_unique.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
begin;
create table public.works(
work_id int primary key
);
create table public.readthroughs (
readthrough_id int primary key,
work_id int not null references public.works(work_id),
status text not null
);
select jsonb_pretty(
graphql.resolve($$
{
__type(name: "Works") {
kind
fields {
name
type {
kind
name
}
}
}
}
$$)
);
jsonb_pretty
-------------------------------------------------------
{ +
"data": { +
"__type": { +
"kind": "OBJECT", +
"fields": [ +
{ +
"name": "nodeId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "workId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "readthroughsCollection",+
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
} +
] +
} +
} +
}
(1 row)

/* Creating partial unique referencing status should NOT change the relationship with
the readthroughs to a non-null unique because its partial and other statuses may
have multiple associated readthroughs */
create unique index idx_unique_in_progress_readthrough
on public.readthroughs (work_id)
where status in ('in_progress');
select jsonb_pretty(
graphql.resolve($$
{
__type(name: "Works") {
kind
fields {
name
type {
kind
name
}
}
}
}
$$)
);
jsonb_pretty
-------------------------------------------------------
{ +
"data": { +
"__type": { +
"kind": "OBJECT", +
"fields": [ +
{ +
"name": "nodeId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "workId", +
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
}, +
{ +
"name": "readthroughsCollection",+
"type": { +
"kind": "NON_NULL", +
"name": null +
} +
} +
] +
} +
} +
}
(1 row)

rollback;
54 changes: 54 additions & 0 deletions test/sql/issue_542_partial_unique.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
begin;

create table public.works(
work_id int primary key
);

create table public.readthroughs (
readthrough_id int primary key,
work_id int not null references public.works(work_id),
status text not null
);

select jsonb_pretty(
graphql.resolve($$
{
__type(name: "Works") {
kind
fields {
name
type {
kind
name
}
}
}
}
$$)
);

/* Creating partial unique referencing status should NOT change the relationship with
the readthroughs to a non-null unique because its partial and other statuses may
have multiple associated readthroughs */
create unique index idx_unique_in_progress_readthrough
on public.readthroughs (work_id)
where status in ('in_progress');

select jsonb_pretty(
graphql.resolve($$
{
__type(name: "Works") {
kind
fields {
name
type {
kind
name
}
}
}
}
$$)
);

rollback;
Loading