From c35eb7a6c2f506c18de2b47ae3ea2a4af684c977 Mon Sep 17 00:00:00 2001 From: Taimoor Zaeem Date: Mon, 2 Feb 2026 21:57:12 +0500 Subject: [PATCH] test(io): move role fixtures to roles.sql Signed-off-by: Taimoor Zaeem --- test/io/fixtures/load.sql | 24 +----------------------- test/io/fixtures/roles.sql | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 test/io/fixtures/roles.sql diff --git a/test/io/fixtures/load.sql b/test/io/fixtures/load.sql index cbb70f6a1..19c0291c9 100644 --- a/test/io/fixtures/load.sql +++ b/test/io/fixtures/load.sql @@ -1,23 +1,9 @@ \ir db_config.sql +\ir roles.sql set check_function_bodies = false; -- to allow conditionals based on the pg version set search_path to public; -CREATE ROLE postgrest_test_anonymous; -ALTER ROLE :PGUSER SET pgrst.db_anon_role = 'postgrest_test_anonymous'; - -CREATE ROLE postgrest_test_author; - -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'; - -CREATE ROLE postgrest_test_w_superuser_settings; -alter role postgrest_test_w_superuser_settings set log_min_duration_statement = 1; -alter role postgrest_test_w_superuser_settings set log_min_messages = 'fatal'; - DO $do$BEGIN IF (SELECT current_setting('server_version_num')::INT >= 150000) THEN ALTER ROLE postgrest_test_w_superuser_settings SET log_min_duration_sample = 12345; @@ -25,11 +11,6 @@ DO $do$BEGIN END IF; END$do$; -GRANT - postgrest_test_anonymous, postgrest_test_author, - postgrest_test_serializable, postgrest_test_repeatable_read, - postgrest_test_w_superuser_settings TO :PGUSER; - CREATE SCHEMA v1; GRANT USAGE ON SCHEMA v1 TO postgrest_test_anonymous; @@ -129,9 +110,6 @@ as $$ notify pgrst, 'reload schema'; $$; -alter role postgrest_test_anonymous set statement_timeout to '2s'; -alter role postgrest_test_author set statement_timeout to '10s'; - create function change_role_statement_timeout(timeout text) returns void as $_$ begin execute format($$ diff --git a/test/io/fixtures/roles.sql b/test/io/fixtures/roles.sql new file mode 100644 index 000000000..3685f8b7c --- /dev/null +++ b/test/io/fixtures/roles.sql @@ -0,0 +1,25 @@ +DROP ROLE IF EXISTS + postgrest_test_anonymous, postgrest_test_author, + postgrest_test_serializable, postgrest_test_repeatable_read, + postgrest_test_w_superuser_settings; + +CREATE ROLE postgrest_test_anonymous; +CREATE ROLE postgrest_test_author; +CREATE ROLE postgrest_test_serializable; +CREATE ROLE postgrest_test_repeatable_read; +CREATE ROLE postgrest_test_w_superuser_settings; + +GRANT + postgrest_test_anonymous, postgrest_test_author, + postgrest_test_serializable, postgrest_test_repeatable_read, + postgrest_test_w_superuser_settings TO :PGUSER; + +ALTER ROLE :PGUSER SET pgrst.db_anon_role = 'postgrest_test_anonymous'; +ALTER ROLE postgrest_test_serializable SET default_transaction_isolation = 'serializable'; +ALTER ROLE postgrest_test_repeatable_read SET default_transaction_isolation = 'REPEATABLE READ'; + +ALTER ROLE postgrest_test_w_superuser_settings SET log_min_duration_statement = 1; +ALTER ROLE postgrest_test_w_superuser_settings SET log_min_messages = 'fatal'; + +ALTER ROLE postgrest_test_anonymous SET statement_timeout TO '2s'; +ALTER ROLE postgrest_test_author SET statement_timeout TO '10s';