-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #543 from supabase/or/issue_542
Partial Unique Indexes should not be marked as `is_unique`
- Loading branch information
Showing
3 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |