Skip to content

test: tests on various docs pages for supabase docs #1675

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
merged 3 commits into from
Jun 26, 2025
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
19 changes: 19 additions & 0 deletions nix/tests/expected/docs-array-test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- testing sql found in https://supabase.com/docs/guides/database/arrays
create table arraytest (
id integer not null,
textarray text array
);
INSERT INTO arraytest (id, textarray) VALUES (1, ARRAY['Harry', 'Larry', 'Moe']);;
select * from arraytest;
id | textarray
----+-------------------
1 | {Harry,Larry,Moe}
(1 row)

SELECT textarray[1], array_length(textarray, 1) FROM arraytest;
textarray | array_length
-----------+--------------
Harry | 3
(1 row)

drop table arraytest cascade;
373 changes: 373 additions & 0 deletions nix/tests/expected/docs-cascades-deletes.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,373 @@
-- testing sql found in https://supabase.com/docs/guides/database/postgres/cascades-deletes
-- all of the errors produced by this file are expected
create table grandparent (
id serial primary key,
name text
);
create table parent (
id serial primary key,
name text,
parent_id integer references grandparent (id)
on delete cascade
);
create table child (
id serial primary key,
name text,
father integer references parent (id)
on delete restrict
);
insert into grandparent
(id, name)
values
(1, 'Elizabeth');
insert into parent
(id, name, parent_id)
values
(1, 'Charles', 1);
insert into parent
(id, name, parent_id)
values
(2, 'Diana', 1);
insert into child
(id, name, father)
values
(1, 'William', 1);
select count(*) from grandparent;
count
-------
1
(1 row)

select count(*) from parent;
count
-------
2
(1 row)

select count(*) from child;
count
-------
1
(1 row)

delete from grandparent;
ERROR: update or delete on table "parent" violates foreign key constraint "child_father_fkey" on table "child"
DETAIL: Key (id)=(1) is still referenced from table "child".
select count(*) from grandparent;
count
-------
1
(1 row)

select count(*) from parent;
count
-------
2
(1 row)

select count(*) from child;
count
-------
1
(1 row)

insert into grandparent
(id, name)
values
(1, 'Elizabeth');
ERROR: duplicate key value violates unique constraint "grandparent_pkey"
DETAIL: Key (id)=(1) already exists.
insert into parent
(id, name, parent_id)
values
(1, 'Charles', 1);
ERROR: duplicate key value violates unique constraint "parent_pkey"
DETAIL: Key (id)=(1) already exists.
insert into parent
(id, name, parent_id)
values
(2, 'Diana', 1);
ERROR: duplicate key value violates unique constraint "parent_pkey"
DETAIL: Key (id)=(2) already exists.
insert into child
(id, name, father)
values
(1, 'William', 1);
ERROR: duplicate key value violates unique constraint "child_pkey"
DETAIL: Key (id)=(1) already exists.
alter table child
drop constraint child_father_fkey;
alter table child
add constraint child_father_fkey foreign key (father) references parent (id)
on delete no action;
delete from grandparent;
ERROR: update or delete on table "parent" violates foreign key constraint "child_father_fkey" on table "child"
DETAIL: Key (id)=(1) is still referenced from table "child".
select count(*) from grandparent;
count
-------
1
(1 row)

select count(*) from parent;
count
-------
2
(1 row)

select count(*) from child;
count
-------
1
(1 row)

insert into grandparent
(id, name)
values
(1, 'Elizabeth');
ERROR: duplicate key value violates unique constraint "grandparent_pkey"
DETAIL: Key (id)=(1) already exists.
insert into parent
(id, name, parent_id)
values
(1, 'Charles', 1);
ERROR: duplicate key value violates unique constraint "parent_pkey"
DETAIL: Key (id)=(1) already exists.
insert into parent
(id, name, parent_id)
values
(2, 'Diana', 1);
ERROR: duplicate key value violates unique constraint "parent_pkey"
DETAIL: Key (id)=(2) already exists.
insert into child
(id, name, father)
values
(1, 'William', 1);
ERROR: duplicate key value violates unique constraint "child_pkey"
DETAIL: Key (id)=(1) already exists.
alter table child
drop constraint child_father_fkey;
alter table child
add constraint child_father_fkey foreign key (father) references parent (id)
on delete no action initially deferred;
delete from grandparent;
ERROR: update or delete on table "parent" violates foreign key constraint "child_father_fkey" on table "child"
DETAIL: Key (id)=(1) is still referenced from table "child".
select count(*) from grandparent;
count
-------
1
(1 row)

select count(*) from parent;
count
-------
2
(1 row)

select count(*) from child;
count
-------
1
(1 row)

insert into grandparent
(id, name)
values
(1, 'Elizabeth');
ERROR: duplicate key value violates unique constraint "grandparent_pkey"
DETAIL: Key (id)=(1) already exists.
insert into parent
(id, name, parent_id)
values
(1, 'Charles', 1);
ERROR: duplicate key value violates unique constraint "parent_pkey"
DETAIL: Key (id)=(1) already exists.
insert into parent
(id, name, parent_id)
values
(2, 'Diana', 1);
ERROR: duplicate key value violates unique constraint "parent_pkey"
DETAIL: Key (id)=(2) already exists.
insert into child
(id, name, father)
values
(1, 'William', 1);
ERROR: duplicate key value violates unique constraint "child_pkey"
DETAIL: Key (id)=(1) already exists.
alter table child
add column mother integer references parent (id)
on delete cascade;
update child
set mother = 2
where id = 1;
delete from grandparent;
select count(*) from grandparent;
count
-------
0
(1 row)

select count(*) from parent;
count
-------
0
(1 row)

select count(*) from child;
count
-------
0
(1 row)

create table test_cascade (
id serial primary key,
name text
);
create table test_cascade_child (
id serial primary key,
parent_id integer references test_cascade (id) on delete cascade,
name text
);
insert into test_cascade (name) values ('Parent');
insert into test_cascade_child (parent_id, name) values (1, 'Child');
delete from test_cascade;
select count(*) from test_cascade;
count
-------
0
(1 row)

select count(*) from test_cascade_child;
count
-------
0
(1 row)

create table test_restrict (
id serial primary key,
name text
);
create table test_restrict_child (
id serial primary key,
parent_id integer references test_restrict (id) on delete restrict,
name text
);
insert into test_restrict (name) values ('Parent');
insert into test_restrict_child (parent_id, name) values (1, 'Child');
delete from test_restrict;
ERROR: update or delete on table "test_restrict" violates foreign key constraint "test_restrict_child_parent_id_fkey" on table "test_restrict_child"
DETAIL: Key (id)=(1) is still referenced from table "test_restrict_child".
select count(*) from test_restrict;
count
-------
1
(1 row)

select count(*) from test_restrict_child;
count
-------
1
(1 row)

create table test_set_null (
id serial primary key,
name text
);
create table test_set_null_child (
id serial primary key,
parent_id integer references test_set_null (id) on delete set null,
name text
);
insert into test_set_null (name) values ('Parent');
insert into test_set_null_child (parent_id, name) values (1, 'Child');
delete from test_set_null;
select count(*) from test_set_null;
count
-------
0
(1 row)

select count(*) from test_set_null_child;
count
-------
1
(1 row)

select parent_id from test_set_null_child;
parent_id
-----------

(1 row)

create table test_set_default (
id serial primary key,
name text
);
create table test_set_default_child (
id serial primary key,
parent_id integer default 999 references test_set_default (id) on delete set default,
name text
);
insert into test_set_default (name) values ('Parent');
insert into test_set_default_child (parent_id, name) values (1, 'Child');
delete from test_set_default;
ERROR: insert or update on table "test_set_default_child" violates foreign key constraint "test_set_default_child_parent_id_fkey"
DETAIL: Key (parent_id)=(999) is not present in table "test_set_default".
select count(*) from test_set_default;
count
-------
1
(1 row)

select count(*) from test_set_default_child;
count
-------
1
(1 row)

select parent_id from test_set_default_child;
parent_id
-----------
1
(1 row)

create table test_no_action (
id serial primary key,
name text
);
create table test_no_action_child (
id serial primary key,
parent_id integer references test_no_action (id) on delete no action,
name text
);
insert into test_no_action (name) values ('Parent');
insert into test_no_action_child (parent_id, name) values (1, 'Child');
delete from test_no_action;
ERROR: update or delete on table "test_no_action" violates foreign key constraint "test_no_action_child_parent_id_fkey" on table "test_no_action_child"
DETAIL: Key (id)=(1) is still referenced from table "test_no_action_child".
select count(*) from test_no_action;
count
-------
1
(1 row)

select count(*) from test_no_action_child;
count
-------
1
(1 row)

drop table if exists test_cascade_child;
drop table if exists test_cascade;
drop table if exists test_restrict_child;
drop table if exists test_restrict;
drop table if exists test_set_null_child;
drop table if exists test_set_null;
drop table if exists test_set_default_child;
drop table if exists test_set_default;
drop table if exists test_no_action_child;
drop table if exists test_no_action;
drop table if exists child;
drop table if exists parent;
drop table if exists grandparent;
Loading