Skip to content

Commit 0b1c39b

Browse files
authored
Merge pull request #543 from supabase/or/issue_542
Partial Unique Indexes should not be marked as `is_unique`
2 parents 37081f9 + 452a5d1 commit 0b1c39b

File tree

3 files changed

+171
-1
lines changed

3 files changed

+171
-1
lines changed

sql/load_sql_context.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ select
280280
),
281281
array[]::text[]
282282
),
283-
'is_unique', pi.indisunique,
283+
'is_unique', pi.indisunique and pi.indpred is null,
284284
'is_primary_key', pi.indisprimary
285285
)
286286
)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
begin;
2+
create table public.works(
3+
work_id int primary key
4+
);
5+
create table public.readthroughs (
6+
readthrough_id int primary key,
7+
work_id int not null references public.works(work_id),
8+
status text not null
9+
);
10+
select jsonb_pretty(
11+
graphql.resolve($$
12+
{
13+
__type(name: "Works") {
14+
kind
15+
fields {
16+
name
17+
type {
18+
kind
19+
name
20+
}
21+
}
22+
}
23+
}
24+
$$)
25+
);
26+
jsonb_pretty
27+
-------------------------------------------------------
28+
{ +
29+
"data": { +
30+
"__type": { +
31+
"kind": "OBJECT", +
32+
"fields": [ +
33+
{ +
34+
"name": "nodeId", +
35+
"type": { +
36+
"kind": "NON_NULL", +
37+
"name": null +
38+
} +
39+
}, +
40+
{ +
41+
"name": "workId", +
42+
"type": { +
43+
"kind": "NON_NULL", +
44+
"name": null +
45+
} +
46+
}, +
47+
{ +
48+
"name": "readthroughsCollection",+
49+
"type": { +
50+
"kind": "NON_NULL", +
51+
"name": null +
52+
} +
53+
} +
54+
] +
55+
} +
56+
} +
57+
}
58+
(1 row)
59+
60+
/* Creating partial unique referencing status should NOT change the relationship with
61+
the readthroughs to a non-null unique because its partial and other statuses may
62+
have multiple associated readthroughs */
63+
create unique index idx_unique_in_progress_readthrough
64+
on public.readthroughs (work_id)
65+
where status in ('in_progress');
66+
select jsonb_pretty(
67+
graphql.resolve($$
68+
{
69+
__type(name: "Works") {
70+
kind
71+
fields {
72+
name
73+
type {
74+
kind
75+
name
76+
}
77+
}
78+
}
79+
}
80+
$$)
81+
);
82+
jsonb_pretty
83+
-------------------------------------------------------
84+
{ +
85+
"data": { +
86+
"__type": { +
87+
"kind": "OBJECT", +
88+
"fields": [ +
89+
{ +
90+
"name": "nodeId", +
91+
"type": { +
92+
"kind": "NON_NULL", +
93+
"name": null +
94+
} +
95+
}, +
96+
{ +
97+
"name": "workId", +
98+
"type": { +
99+
"kind": "NON_NULL", +
100+
"name": null +
101+
} +
102+
}, +
103+
{ +
104+
"name": "readthroughsCollection",+
105+
"type": { +
106+
"kind": "NON_NULL", +
107+
"name": null +
108+
} +
109+
} +
110+
] +
111+
} +
112+
} +
113+
}
114+
(1 row)
115+
116+
rollback;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
begin;
2+
3+
create table public.works(
4+
work_id int primary key
5+
);
6+
7+
create table public.readthroughs (
8+
readthrough_id int primary key,
9+
work_id int not null references public.works(work_id),
10+
status text not null
11+
);
12+
13+
select jsonb_pretty(
14+
graphql.resolve($$
15+
{
16+
__type(name: "Works") {
17+
kind
18+
fields {
19+
name
20+
type {
21+
kind
22+
name
23+
}
24+
}
25+
}
26+
}
27+
$$)
28+
);
29+
30+
/* Creating partial unique referencing status should NOT change the relationship with
31+
the readthroughs to a non-null unique because its partial and other statuses may
32+
have multiple associated readthroughs */
33+
create unique index idx_unique_in_progress_readthrough
34+
on public.readthroughs (work_id)
35+
where status in ('in_progress');
36+
37+
select jsonb_pretty(
38+
graphql.resolve($$
39+
{
40+
__type(name: "Works") {
41+
kind
42+
fields {
43+
name
44+
type {
45+
kind
46+
name
47+
}
48+
}
49+
}
50+
}
51+
$$)
52+
);
53+
54+
rollback;

0 commit comments

Comments
 (0)