Regression tests for SCHEMA commands
Hari Babu Kommi reviewed by David Rowley
This commit is contained in:
parent
b921a26fb8
commit
cf589c9c1f
|
@ -36,24 +36,7 @@ SELECT * FROM test_schema_1.abc_view;
|
||||||
4 |
|
4 |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
-- test IF NOT EXISTS cases
|
ALTER SCHEMA test_schema_1 RENAME TO test_schema_renamed;
|
||||||
CREATE SCHEMA test_schema_1; -- fail, already exists
|
|
||||||
ERROR: schema "test_schema_1" already exists
|
|
||||||
CREATE SCHEMA IF NOT EXISTS test_schema_1; -- ok with notice
|
|
||||||
NOTICE: schema "test_schema_1" already exists, skipping
|
|
||||||
CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed
|
|
||||||
CREATE TABLE abc (
|
|
||||||
a serial,
|
|
||||||
b int UNIQUE
|
|
||||||
);
|
|
||||||
ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements
|
|
||||||
LINE 2: CREATE TABLE abc (
|
|
||||||
^
|
|
||||||
DROP SCHEMA test_schema_1 CASCADE;
|
|
||||||
NOTICE: drop cascades to 2 other objects
|
|
||||||
DETAIL: drop cascades to table test_schema_1.abc
|
|
||||||
drop cascades to view test_schema_1.abc_view
|
|
||||||
-- 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_1');
|
||||||
count
|
count
|
||||||
|
@ -61,3 +44,28 @@ SELECT COUNT(*) FROM pg_class WHERE relnamespace =
|
||||||
0
|
0
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- test IF NOT EXISTS cases
|
||||||
|
CREATE SCHEMA test_schema_renamed; -- fail, already exists
|
||||||
|
ERROR: schema "test_schema_renamed" already exists
|
||||||
|
CREATE SCHEMA IF NOT EXISTS test_schema_renamed; -- ok with notice
|
||||||
|
NOTICE: schema "test_schema_renamed" already exists, skipping
|
||||||
|
CREATE SCHEMA IF NOT EXISTS test_schema_renamed -- fail, disallowed
|
||||||
|
CREATE TABLE abc (
|
||||||
|
a serial,
|
||||||
|
b int UNIQUE
|
||||||
|
);
|
||||||
|
ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements
|
||||||
|
LINE 2: CREATE TABLE abc (
|
||||||
|
^
|
||||||
|
DROP SCHEMA test_schema_renamed CASCADE;
|
||||||
|
NOTICE: drop cascades to 2 other objects
|
||||||
|
DETAIL: drop cascades to table test_schema_renamed.abc
|
||||||
|
drop cascades to view test_schema_renamed.abc_view
|
||||||
|
-- verify that the objects were dropped
|
||||||
|
SELECT COUNT(*) FROM pg_class WHERE relnamespace =
|
||||||
|
(SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_renamed');
|
||||||
|
count
|
||||||
|
-------
|
||||||
|
0
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
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;
|
||||||
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 -
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue