feat: isolation level for roles/functions
This commit is contained in:
committed by
Steve Chavez
parent
4c555cbd5d
commit
aaf77902f6
+35
-1
@@ -8,7 +8,13 @@ ALTER ROLE :USER SET pgrst.db_anon_role = 'postgrest_test_anonymous';
|
||||
|
||||
CREATE ROLE postgrest_test_author;
|
||||
|
||||
GRANT postgrest_test_anonymous, postgrest_test_author TO :USER;
|
||||
CREATE ROLE postgrest_test_serializable;
|
||||
alter role postgrest_test_serializable set default_transaction_isolation = 'serializable';
|
||||
|
||||
CREATE ROLE postgrest_test_repeatable_read;
|
||||
alter role postgrest_test_repeatable_read set default_transaction_isolation = 'REPEATABLE READ';
|
||||
|
||||
GRANT postgrest_test_anonymous, postgrest_test_author, postgrest_test_serializable, postgrest_test_repeatable_read TO :USER;
|
||||
|
||||
CREATE SCHEMA v1;
|
||||
GRANT USAGE ON SCHEMA v1 TO postgrest_test_anonymous;
|
||||
@@ -108,3 +114,31 @@ begin
|
||||
alter role current_user set statement_timeout = %L;
|
||||
$$, timeout);
|
||||
end $_$ volatile language plpgsql ;
|
||||
|
||||
create table items as select x as id from generate_series(1,5) x;
|
||||
|
||||
create view items_w_isolation_level as
|
||||
select
|
||||
id,
|
||||
current_setting('transaction_isolation', true) as isolation_level
|
||||
from items;
|
||||
|
||||
grant all on items_w_isolation_level to postgrest_test_anonymous, postgrest_test_repeatable_read, postgrest_test_serializable;
|
||||
|
||||
create function default_isolation_level()
|
||||
returns text as $$
|
||||
select current_setting('transaction_isolation', true);
|
||||
$$
|
||||
language sql;
|
||||
|
||||
create function serializable_isolation_level()
|
||||
returns text as $$
|
||||
select current_setting('transaction_isolation', true);
|
||||
$$
|
||||
language sql set default_transaction_isolation = 'serializable';
|
||||
|
||||
create function repeatable_read_isolation_level()
|
||||
returns text as $$
|
||||
select current_setting('transaction_isolation', true);
|
||||
$$
|
||||
language sql set default_transaction_isolation = 'REPEATABLE READ';
|
||||
|
||||
Reference in New Issue
Block a user