Skip to content
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
18 changes: 9 additions & 9 deletions sql/test_factory--0.5.0.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* DO NOT EDIT - AUTO-GENERATED FILE */
CREATE TEMP TABLE original_role ON COMMIT DROP AS SELECT current_user AS original_role;

GRANT SELECT ON pg_temp.original_role TO public;
/*
* Save the caller's role so we can restore it at the end (we SET LOCAL ROLE
* below to own our objects). A GUC is used instead of a temp table not to
* avoid CREATE EXTENSION breakage (trivial to avoid either way) but because
* it's much lighter weight than creating a table.
*/
SELECT pg_catalog.set_config('test_factory.original_role', current_user, true);
DO $body$
BEGIN
CREATE ROLE test_factory__owner;
Expand Down Expand Up @@ -250,15 +254,11 @@ END
$body$;

--select (tf.get('moo','moo')::moo).*;
-- Restore the caller's role saved at the top of this script.
DO $body$
DECLARE
c_sql CONSTANT text := 'SET ROLE ' || (SELECT original_role FROM pg_temp.original_role);
BEGIN
--RAISE WARNING 'c_sql = %', c_sql;
EXECUTE c_sql;
EXECUTE 'SET ROLE ' || pg_catalog.quote_ident(pg_catalog.current_setting('test_factory.original_role'));
END
$body$;

DROP TABLE pg_temp.original_role;

-- vi: expandtab ts=2 sw=2
18 changes: 9 additions & 9 deletions sql/test_factory.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CREATE TEMP TABLE original_role ON COMMIT DROP AS SELECT current_user AS original_role;

GRANT SELECT ON pg_temp.original_role TO public;
/*
* Save the caller's role so we can restore it at the end (we SET LOCAL ROLE
* below to own our objects). A GUC is used instead of a temp table not to
* avoid CREATE EXTENSION breakage (trivial to avoid either way) but because
* it's much lighter weight than creating a table.
*/
SELECT pg_catalog.set_config('test_factory.original_role', current_user, true);
DO $body$
BEGIN
CREATE ROLE test_factory__owner;
Expand Down Expand Up @@ -249,15 +253,11 @@ END
$body$;

--select (tf.get('moo','moo')::moo).*;
-- Restore the caller's role saved at the top of this script.
DO $body$
DECLARE
c_sql CONSTANT text := 'SET ROLE ' || (SELECT original_role FROM pg_temp.original_role);
BEGIN
--RAISE WARNING 'c_sql = %', c_sql;
EXECUTE c_sql;
EXECUTE 'SET ROLE ' || pg_catalog.quote_ident(pg_catalog.current_setting('test_factory.original_role'));
END
$body$;

DROP TABLE pg_temp.original_role;

-- vi: expandtab ts=2 sw=2
18 changes: 9 additions & 9 deletions sql/test_factory_pgtap--0.1.0.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* DO NOT EDIT - AUTO-GENERATED FILE */
CREATE TEMP TABLE original_role ON COMMIT DROP AS SELECT current_user AS original_role;
GRANT SELECT ON pg_temp.original_role TO public;
/*
* Save the caller's role so we can restore it at the end (we SET LOCAL ROLE
* below to own our objects). A GUC is used instead of a temp table not to
* avoid CREATE EXTENSION breakage (trivial to avoid either way) but because
* it's much lighter weight than creating a table.
*/
SELECT pg_catalog.set_config('test_factory_pgtap.original_role', current_user, true);

SET LOCAL ROLE test_factory__owner;

Expand All @@ -26,16 +31,11 @@ BEGIN
END
$body$;

-- Set role back to original value
-- Set role back to original value (saved at the top of this script).
DO $body$
DECLARE
c_sql CONSTANT text := 'SET ROLE ' || (SELECT original_role FROM pg_temp.original_role);
BEGIN
--RAISE WARNING 'c_sql = %', c_sql;
EXECUTE c_sql;
EXECUTE 'SET ROLE ' || pg_catalog.quote_ident(pg_catalog.current_setting('test_factory_pgtap.original_role'));
END
$body$;

DROP TABLE pg_temp.original_role;

-- vi: expandtab ts=2 sw=2
18 changes: 9 additions & 9 deletions sql/test_factory_pgtap.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
CREATE TEMP TABLE original_role ON COMMIT DROP AS SELECT current_user AS original_role;
GRANT SELECT ON pg_temp.original_role TO public;
/*
* Save the caller's role so we can restore it at the end (we SET LOCAL ROLE
* below to own our objects). A GUC is used instead of a temp table not to
* avoid CREATE EXTENSION breakage (trivial to avoid either way) but because
* it's much lighter weight than creating a table.
*/
SELECT pg_catalog.set_config('test_factory_pgtap.original_role', current_user, true);

SET LOCAL ROLE test_factory__owner;

Expand All @@ -25,16 +30,11 @@ BEGIN
END
$body$;

-- Set role back to original value
-- Set role back to original value (saved at the top of this script).
DO $body$
DECLARE
c_sql CONSTANT text := 'SET ROLE ' || (SELECT original_role FROM pg_temp.original_role);
BEGIN
--RAISE WARNING 'c_sql = %', c_sql;
EXECUTE c_sql;
EXECUTE 'SET ROLE ' || pg_catalog.quote_ident(pg_catalog.current_setting('test_factory_pgtap.original_role'));
END
$body$;

DROP TABLE pg_temp.original_role;

-- vi: expandtab ts=2 sw=2
Loading