feat: Include partitioned tables into the schema cache

Allows embedding, UPSERT, INSERT with Location response, OPTIONS request and OpenAPI support for partitioned tables
This commit is contained in:
laurenceisla
2021-08-13 15:06:56 -05:00
committed by GitHub
parent b3899e7aa4
commit 4e4548d702
12 changed files with 351 additions and 49 deletions
+25
View File
@@ -663,3 +663,28 @@ INSERT INTO private.films (id, title) VALUES (12,'douze commandements'), (2001,'
TRUNCATE TABLE private.personnages CASCADE;
INSERT INTO private.personnages (film_id, role_id, character) VALUES (12,1,'méchant'), (2001,2,'astronaute');
DO $do$BEGIN
IF (SELECT current_setting('server_version_num')::INT >= 100000) THEN
INSERT INTO test.partitioned_a(id, name) VALUES (1,'first');
INSERT INTO test.partitioned_a(id, name) VALUES (2,'first');
INSERT INTO test.partitioned_a(id, name) VALUES (3,'second');
INSERT INTO test.partitioned_a(id, name) VALUES (4,'second');
END IF;
IF (SELECT current_setting('server_version_num')::INT >= 110000) THEN
INSERT INTO test.reference_from_partitioned(id) VALUES (1),(2);
UPDATE test.partitioned_a SET id_ref = 1 WHERE id = 1;
END IF;
IF (SELECT current_setting('server_version_num')::INT >= 120000) THEN
INSERT INTO test.partitioned_b(id, name) VALUES (1,'first_b');
INSERT INTO test.partitioned_b(id, name, id_a, name_a) VALUES (2,'first_b', 2, 'first');
INSERT INTO test.partitioned_b(id, name) VALUES (3,'second_b');
INSERT INTO test.partitioned_b(id, name, id_a, name_a) VALUES (4,'second_b', 4, 'second');
INSERT INTO test.reference_to_partitioned(id) VALUES (1);
INSERT INTO test.reference_to_partitioned(id, id_a, name_a) VALUES (2, 2, 'first');
END IF;
END$do$;
+20
View File
@@ -179,3 +179,23 @@ REVOKE EXECUTE ON FUNCTION privileged_hello(text) FROM PUBLIC; -- All functions
GRANT EXECUTE ON FUNCTION privileged_hello(text) TO postgrest_test_author;
GRANT USAGE ON SCHEMA test TO postgrest_test_default_role;
DO $do$BEGIN
IF (SELECT current_setting('server_version_num')::INT >= 100000) THEN
GRANT ALL ON TABLE test.partitioned_a TO postgrest_test_anonymous;
GRANT ALL ON TABLE test.first_partition_a TO postgrest_test_anonymous;
GRANT ALL ON TABLE test.second_partition_a TO postgrest_test_anonymous;
END IF;
IF (SELECT current_setting('server_version_num')::INT >= 110000) THEN
GRANT ALL ON TABLE test.reference_from_partitioned TO postgrest_test_anonymous;
END IF;
IF (SELECT current_setting('server_version_num')::INT >= 120000) THEN
GRANT ALL ON TABLE test.partitioned_b TO postgrest_test_anonymous;
GRANT ALL ON TABLE test.first_partition_b TO postgrest_test_anonymous;
GRANT ALL ON TABLE test.second_partition_b TO postgrest_test_anonymous;
GRANT ALL ON TABLE test.reference_to_partitioned TO postgrest_test_anonymous;
END IF;
END$do$;
+58
View File
@@ -2185,3 +2185,61 @@ create table private.rollen (
foreign key (film_id) references test.filme(id),
foreign key (rolle_id) references test.schauspieler(id)
);
-- Tables used for testing embedding between partitioned tables
do $do$begin
-- partitioned tables using the PARTITION syntax are supported from pg v10
if (select current_setting('server_version_num')::int >= 100000) then
create table test.partitioned_a(
id int not null,
name varchar(64) not null
) partition by list (name);
comment on table test.partitioned_a is
$$A partitioned table
A test for partitioned tables$$;
create table test.first_partition_a partition of test.partitioned_a
for values in ('first');
create table test.second_partition_a partition of test.partitioned_a
for values in ('second');
end if;
-- primary keys for partitioned tables are supported from pg v11
if (select current_setting('server_version_num')::int >= 110000) then
create table test.reference_from_partitioned (
id int primary key
);
alter table test.partitioned_a add primary key (id, name);
alter table test.partitioned_a add column id_ref int references test.reference_from_partitioned(id);
end if;
-- foreign keys referencing partitioned tables are supported from pg v12
if (select current_setting('server_version_num')::int >= 120000) then
create table test.partitioned_b(
id int not null,
name varchar(64) not null,
id_a int,
name_a varchar(64),
primary key (id, name),
foreign key (id_a, name_a) references test.partitioned_a (id, name)
) partition by list (name);
create table test.first_partition_b partition of test.partitioned_b
for values in ('first_b');
create table test.second_partition_b partition of test.partitioned_b
for values in ('second_b');
create table test.reference_to_partitioned (
id int not null primary key,
id_a int,
name_a varchar(64),
foreign key (id_a, name_a) references test.partitioned_a (id, name)
);
end if;
end$do$;