mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Add CASCADE support for CREATE EXTENSION.
Without CASCADE, if an extension has an unfullfilled dependency on another extension, CREATE EXTENSION ERRORs out with "required extension ... is not installed". That is annoying, especially when that dependency is an implementation detail of the extension, rather than something the extension's user can make sense of. In addition to CASCADE this also includes a small set of regression tests around CREATE EXTENSION. Author: Petr Jelinek, editorialized by Michael Paquier, Andres Freund Reviewed-By: Michael Paquier, Andres Freund, Jeff Janes Discussion: 557E0520.3040800@2ndquadrant.com
This commit is contained in:
@ -9,6 +9,7 @@ SUBDIRS = \
|
||||
commit_ts \
|
||||
dummy_seclabel \
|
||||
test_ddl_deparse \
|
||||
test_extensions \
|
||||
test_parser \
|
||||
test_rls_hooks \
|
||||
test_shm_mq \
|
||||
|
4
src/test/modules/test_extensions/.gitignore
vendored
Normal file
4
src/test/modules/test_extensions/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# Generated subdirectories
|
||||
/log/
|
||||
/results/
|
||||
/tmp_check/
|
23
src/test/modules/test_extensions/Makefile
Normal file
23
src/test/modules/test_extensions/Makefile
Normal file
@ -0,0 +1,23 @@
|
||||
# src/test/modules/test_extensions/Makefile
|
||||
|
||||
MODULE = test_extensions
|
||||
PGFILEDESC = "test_extensions - regression testing for EXTENSION support"
|
||||
|
||||
EXTENSION = test_ext1 test_ext2 test_ext3 test_ext4 test_ext5 \
|
||||
test_ext_cyclic1 test_ext_cyclic2
|
||||
DATA = test_ext1--1.0.sql test_ext2--1.0.sql test_ext3--1.0.sql \
|
||||
test_ext4--1.0.sql test_ext5--1.0.sql test_ext_cyclic1--1.0.sql \
|
||||
test_ext_cyclic2--1.0.sql
|
||||
|
||||
REGRESS = test_extensions
|
||||
|
||||
ifdef USE_PGXS
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
else
|
||||
subdir = src/test/modules/test_extensions
|
||||
top_builddir = ../../../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
endif
|
@ -0,0 +1,37 @@
|
||||
-- test some errors
|
||||
CREATE EXTENSION test_ext1;
|
||||
ERROR: required extension "test_ext2" is not installed
|
||||
HINT: Use CREATE EXTENSION CASCADE to install required extensions too.
|
||||
CREATE EXTENSION test_ext1 SCHEMA test_ext1;
|
||||
ERROR: schema "test_ext1" does not exist
|
||||
CREATE EXTENSION test_ext1 SCHEMA test_ext;
|
||||
ERROR: schema "test_ext" does not exist
|
||||
CREATE SCHEMA test_ext;
|
||||
CREATE EXTENSION test_ext1 SCHEMA test_ext;
|
||||
ERROR: extension "test_ext1" must be installed in schema "test_ext1"
|
||||
-- finally success
|
||||
CREATE EXTENSION test_ext1 SCHEMA test_ext CASCADE;
|
||||
NOTICE: installing required extension "test_ext2"
|
||||
NOTICE: installing required extension "test_ext3"
|
||||
NOTICE: installing required extension "test_ext5"
|
||||
NOTICE: installing required extension "test_ext4"
|
||||
SELECT extname, nspname, extversion, extrelocatable FROM pg_extension e, pg_namespace n WHERE extname LIKE 'test_ext%' AND e.extnamespace = n.oid ORDER BY 1;
|
||||
extname | nspname | extversion | extrelocatable
|
||||
-----------+-----------+------------+----------------
|
||||
test_ext1 | test_ext1 | 1.0 | f
|
||||
test_ext2 | test_ext | 1.0 | t
|
||||
test_ext3 | test_ext | 1.0 | t
|
||||
test_ext4 | test_ext | 1.0 | t
|
||||
test_ext5 | test_ext | 1.0 | t
|
||||
(5 rows)
|
||||
|
||||
CREATE EXTENSION test_ext_cyclic1 CASCADE;
|
||||
NOTICE: installing required extension "test_ext_cyclic2"
|
||||
ERROR: cyclic dependency detected between extensions "test_ext_cyclic1" and "test_ext_cyclic2"
|
||||
DROP SCHEMA test_ext CASCADE;
|
||||
NOTICE: drop cascades to 5 other objects
|
||||
DETAIL: drop cascades to extension test_ext3
|
||||
drop cascades to extension test_ext5
|
||||
drop cascades to extension test_ext2
|
||||
drop cascades to extension test_ext4
|
||||
drop cascades to extension test_ext1
|
15
src/test/modules/test_extensions/sql/test_extensions.sql
Normal file
15
src/test/modules/test_extensions/sql/test_extensions.sql
Normal file
@ -0,0 +1,15 @@
|
||||
-- test some errors
|
||||
CREATE EXTENSION test_ext1;
|
||||
CREATE EXTENSION test_ext1 SCHEMA test_ext1;
|
||||
CREATE EXTENSION test_ext1 SCHEMA test_ext;
|
||||
CREATE SCHEMA test_ext;
|
||||
CREATE EXTENSION test_ext1 SCHEMA test_ext;
|
||||
|
||||
-- finally success
|
||||
CREATE EXTENSION test_ext1 SCHEMA test_ext CASCADE;
|
||||
|
||||
SELECT extname, nspname, extversion, extrelocatable FROM pg_extension e, pg_namespace n WHERE extname LIKE 'test_ext%' AND e.extnamespace = n.oid ORDER BY 1;
|
||||
|
||||
CREATE EXTENSION test_ext_cyclic1 CASCADE;
|
||||
|
||||
DROP SCHEMA test_ext CASCADE;
|
3
src/test/modules/test_extensions/test_ext1--1.0.sql
Normal file
3
src/test/modules/test_extensions/test_ext1--1.0.sql
Normal file
@ -0,0 +1,3 @@
|
||||
/* src/test/modules/test_extensions/test_ext1--1.0.sql */
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION test_ext1" to load this file. \quit
|
5
src/test/modules/test_extensions/test_ext1.control
Normal file
5
src/test/modules/test_extensions/test_ext1.control
Normal file
@ -0,0 +1,5 @@
|
||||
comment = 'Test extension 1'
|
||||
default_version = '1.0'
|
||||
schema = 'test_ext1'
|
||||
relocatable = false
|
||||
requires = 'test_ext2,test_ext4'
|
3
src/test/modules/test_extensions/test_ext2--1.0.sql
Normal file
3
src/test/modules/test_extensions/test_ext2--1.0.sql
Normal file
@ -0,0 +1,3 @@
|
||||
/* src/test/modules/test_extensions/test_ext2--1.0.sql */
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION test_ext2" to load this file. \quit
|
4
src/test/modules/test_extensions/test_ext2.control
Normal file
4
src/test/modules/test_extensions/test_ext2.control
Normal file
@ -0,0 +1,4 @@
|
||||
comment = 'Test extension 2'
|
||||
default_version = '1.0'
|
||||
relocatable = true
|
||||
requires = 'test_ext3,test_ext5'
|
3
src/test/modules/test_extensions/test_ext3--1.0.sql
Normal file
3
src/test/modules/test_extensions/test_ext3--1.0.sql
Normal file
@ -0,0 +1,3 @@
|
||||
/* src/test/modules/test_extensions/test_ext3--1.0.sql */
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION test_ext3" to load this file. \quit
|
3
src/test/modules/test_extensions/test_ext3.control
Normal file
3
src/test/modules/test_extensions/test_ext3.control
Normal file
@ -0,0 +1,3 @@
|
||||
comment = 'Test extension 3'
|
||||
default_version = '1.0'
|
||||
relocatable = true
|
3
src/test/modules/test_extensions/test_ext4--1.0.sql
Normal file
3
src/test/modules/test_extensions/test_ext4--1.0.sql
Normal file
@ -0,0 +1,3 @@
|
||||
/* src/test/modules/test_extensions/test_ext4--1.0.sql */
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION test_ext4" to load this file. \quit
|
4
src/test/modules/test_extensions/test_ext4.control
Normal file
4
src/test/modules/test_extensions/test_ext4.control
Normal file
@ -0,0 +1,4 @@
|
||||
comment = 'Test extension 4'
|
||||
default_version = '1.0'
|
||||
relocatable = true
|
||||
requires = 'test_ext5'
|
3
src/test/modules/test_extensions/test_ext5--1.0.sql
Normal file
3
src/test/modules/test_extensions/test_ext5--1.0.sql
Normal file
@ -0,0 +1,3 @@
|
||||
/* src/test/modules/test_extensions/test_ext5--1.0.sql */
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION test_ext5" to load this file. \quit
|
3
src/test/modules/test_extensions/test_ext5.control
Normal file
3
src/test/modules/test_extensions/test_ext5.control
Normal file
@ -0,0 +1,3 @@
|
||||
comment = 'Test extension 5'
|
||||
default_version = '1.0'
|
||||
relocatable = true
|
@ -0,0 +1,3 @@
|
||||
/* src/test/modules/test_extensions/test_ext_cyclic1--1.0.sql */
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION test_ext_cyclic1" to load this file. \quit
|
@ -0,0 +1,4 @@
|
||||
comment = 'Test extension cyclic 1'
|
||||
default_version = '1.0'
|
||||
relocatable = true
|
||||
requires = 'test_ext_cyclic2'
|
@ -0,0 +1,3 @@
|
||||
/* src/test/modules/test_extensions/test_ext_cyclic2--1.0.sql */
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION test_ext_cyclic2" to load this file. \quit
|
@ -0,0 +1,4 @@
|
||||
comment = 'Test extension cyclic 2'
|
||||
default_version = '1.0'
|
||||
relocatable = true
|
||||
requires = 'test_ext_cyclic1'
|
Reference in New Issue
Block a user