Commit cf589c9c authored by Simon Riggs's avatar Simon Riggs

Regression tests for SCHEMA commands

Hari Babu Kommi reviewed by David Rowley
parent b921a26f
...@@ -36,12 +36,20 @@ SELECT * FROM test_schema_1.abc_view; ...@@ -36,12 +36,20 @@ SELECT * FROM test_schema_1.abc_view;
4 | 4 |
(3 rows) (3 rows)
ALTER SCHEMA test_schema_1 RENAME TO test_schema_renamed;
SELECT COUNT(*) FROM pg_class WHERE relnamespace =
(SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
count
-------
0
(1 row)
-- test IF NOT EXISTS cases -- test IF NOT EXISTS cases
CREATE SCHEMA test_schema_1; -- fail, already exists CREATE SCHEMA test_schema_renamed; -- fail, already exists
ERROR: schema "test_schema_1" already exists ERROR: schema "test_schema_renamed" already exists
CREATE SCHEMA IF NOT EXISTS test_schema_1; -- ok with notice CREATE SCHEMA IF NOT EXISTS test_schema_renamed; -- ok with notice
NOTICE: schema "test_schema_1" already exists, skipping NOTICE: schema "test_schema_renamed" already exists, skipping
CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed CREATE SCHEMA IF NOT EXISTS test_schema_renamed -- fail, disallowed
CREATE TABLE abc ( CREATE TABLE abc (
a serial, a serial,
b int UNIQUE b int UNIQUE
...@@ -49,13 +57,13 @@ CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed ...@@ -49,13 +57,13 @@ CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed
ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements
LINE 2: CREATE TABLE abc ( LINE 2: CREATE TABLE abc (
^ ^
DROP SCHEMA test_schema_1 CASCADE; DROP SCHEMA test_schema_renamed CASCADE;
NOTICE: drop cascades to 2 other objects NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table test_schema_1.abc DETAIL: drop cascades to table test_schema_renamed.abc
drop cascades to view test_schema_1.abc_view drop cascades to view test_schema_renamed.abc_view
-- verify that the objects were dropped -- verify that the objects were dropped
SELECT COUNT(*) FROM pg_class WHERE relnamespace = SELECT COUNT(*) FROM pg_class WHERE relnamespace =
(SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1'); (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_renamed');
count count
------- -------
0 0
......
...@@ -1350,6 +1350,34 @@ SELECT has_function_privilege('regressuser1', 'testns.testfunc(int)', 'EXECUTE') ...@@ -1350,6 +1350,34 @@ SELECT has_function_privilege('regressuser1', 'testns.testfunc(int)', 'EXECUTE')
SET client_min_messages TO 'warning'; SET client_min_messages TO 'warning';
DROP SCHEMA testns CASCADE; DROP SCHEMA testns CASCADE;
RESET client_min_messages; RESET client_min_messages;
-- Change owner of the schema & and rename of new schema owner
\c -
CREATE ROLE schemauser1 superuser login;
CREATE ROLE schemauser2 superuser login;
SET SESSION ROLE schemauser1;
CREATE SCHEMA testns;
SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
nspname | rolname
---------+-------------
testns | schemauser1
(1 row)
ALTER SCHEMA testns OWNER TO schemauser2;
ALTER ROLE schemauser2 RENAME TO schemauser_renamed;
SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
nspname | rolname
---------+--------------------
testns | schemauser_renamed
(1 row)
set session role schemauser_renamed;
SET client_min_messages TO 'warning';
DROP SCHEMA testns CASCADE;
RESET client_min_messages;
-- clean up
\c -
DROP ROLE schemauser1;
DROP ROLE schemauser_renamed;
-- test that dependent privileges are revoked (or not) properly -- test that dependent privileges are revoked (or not) properly
\c - \c -
set session role regressuser1; set session role regressuser1;
......
...@@ -24,17 +24,21 @@ INSERT INTO test_schema_1.abc DEFAULT VALUES; ...@@ -24,17 +24,21 @@ INSERT INTO test_schema_1.abc DEFAULT VALUES;
SELECT * FROM test_schema_1.abc; SELECT * FROM test_schema_1.abc;
SELECT * FROM test_schema_1.abc_view; SELECT * FROM test_schema_1.abc_view;
ALTER SCHEMA test_schema_1 RENAME TO test_schema_renamed;
SELECT COUNT(*) FROM pg_class WHERE relnamespace =
(SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
-- test IF NOT EXISTS cases -- test IF NOT EXISTS cases
CREATE SCHEMA test_schema_1; -- fail, already exists CREATE SCHEMA test_schema_renamed; -- fail, already exists
CREATE SCHEMA IF NOT EXISTS test_schema_1; -- ok with notice CREATE SCHEMA IF NOT EXISTS test_schema_renamed; -- ok with notice
CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed CREATE SCHEMA IF NOT EXISTS test_schema_renamed -- fail, disallowed
CREATE TABLE abc ( CREATE TABLE abc (
a serial, a serial,
b int UNIQUE b int UNIQUE
); );
DROP SCHEMA test_schema_1 CASCADE; DROP SCHEMA test_schema_renamed CASCADE;
-- verify that the objects were dropped -- verify that the objects were dropped
SELECT COUNT(*) FROM pg_class WHERE relnamespace = SELECT COUNT(*) FROM pg_class WHERE relnamespace =
(SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1'); (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_renamed');
...@@ -813,6 +813,33 @@ DROP SCHEMA testns CASCADE; ...@@ -813,6 +813,33 @@ DROP SCHEMA testns CASCADE;
RESET client_min_messages; RESET client_min_messages;
-- Change owner of the schema & and rename of new schema owner
\c -
CREATE ROLE schemauser1 superuser login;
CREATE ROLE schemauser2 superuser login;
SET SESSION ROLE schemauser1;
CREATE SCHEMA testns;
SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
ALTER SCHEMA testns OWNER TO schemauser2;
ALTER ROLE schemauser2 RENAME TO schemauser_renamed;
SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
set session role schemauser_renamed;
SET client_min_messages TO 'warning';
DROP SCHEMA testns CASCADE;
RESET client_min_messages;
-- clean up
\c -
DROP ROLE schemauser1;
DROP ROLE schemauser_renamed;
-- test that dependent privileges are revoked (or not) properly -- test that dependent privileges are revoked (or not) properly
\c - \c -
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment