diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index b5630b4c8d..eedecded2e 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -1386,6 +1386,7 @@ CreateExtensionInternal(char *extensionName, List *requiredSchemas; Oid extensionOid; ObjectAddress address; + bool created_schema = false; ListCell *lc; /* @@ -1496,6 +1497,7 @@ CreateExtensionInternal(char *extensionName, csstmt->if_not_exists = false; CreateSchemaCommand(csstmt, "(generated CREATE SCHEMA command)", -1, -1); + created_schema = true; /* * CreateSchemaCommand includes CommandCounterIncrement, so new @@ -1577,6 +1579,18 @@ CreateExtensionInternal(char *extensionName, requiredExtensions); extensionOid = address.objectId; + /* + * Create the dependency between the schema and the extension if the + * schema is newly created. + */ + if (created_schema) + { + ObjectAddress schemaAddr; + + ObjectAddressSet(schemaAddr, NamespaceRelationId, schemaOid); + recordDependencyOn(&schemaAddr, &address, DEPENDENCY_EXTENSION); + } + /* * Apply any control-file comment on extension */ diff --git a/src/test/modules/test_extensions/expected/test_extensions.out b/src/test/modules/test_extensions/expected/test_extensions.out index 30ae621d05..a624642a6f 100644 --- a/src/test/modules/test_extensions/expected/test_extensions.out +++ b/src/test/modules/test_extensions/expected/test_extensions.out @@ -36,7 +36,21 @@ drop cascades to extension test_ext2 drop cascades to extension test_ext4 drop cascades to extension test_ext1 CREATE EXTENSION test_ext6; +-- test if the test_ext6 schema specified in the schema option is created +-- on CREATE EXTENSION. +SELECT nspname FROM pg_namespace WHERE nspname = 'test_ext6'; + nspname +----------- + test_ext6 +(1 row) + DROP EXTENSION test_ext6; +-- test if the test_ext6 schema is also dropped. +SELECT nspname FROM pg_namespace WHERE nspname = 'test_ext6'; + nspname +--------- +(0 rows) + CREATE EXTENSION test_ext6; -- test dropping of member tables that own extensions: -- this table will be absorbed into test_ext7 diff --git a/src/test/modules/test_extensions/sql/test_extensions.sql b/src/test/modules/test_extensions/sql/test_extensions.sql index c16fd36da8..e6dae7d8a7 100644 --- a/src/test/modules/test_extensions/sql/test_extensions.sql +++ b/src/test/modules/test_extensions/sql/test_extensions.sql @@ -15,7 +15,15 @@ CREATE EXTENSION test_ext_cyclic1 CASCADE; DROP SCHEMA test_ext CASCADE; CREATE EXTENSION test_ext6; + +-- test if the test_ext6 schema specified in the schema option is created +-- on CREATE EXTENSION. +SELECT nspname FROM pg_namespace WHERE nspname = 'test_ext6'; DROP EXTENSION test_ext6; + +-- test if the test_ext6 schema is also dropped. +SELECT nspname FROM pg_namespace WHERE nspname = 'test_ext6'; + CREATE EXTENSION test_ext6; -- test dropping of member tables that own extensions: