Skip to content

Commit b67aaf2

Browse files
committed
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: [email protected]
1 parent bf68679 commit b67aaf2

32 files changed

+346
-89
lines changed

Diff for: contrib/hstore_plperl/expected/hstore_plperl.out

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
CREATE EXTENSION hstore;
2-
CREATE EXTENSION plperl;
3-
CREATE EXTENSION hstore_plperl;
1+
CREATE EXTENSION hstore_plperl CASCADE;
2+
NOTICE: installing required extension "hstore"
3+
NOTICE: installing required extension "plperl"
44
SELECT transforms.udt_schema, transforms.udt_name,
55
routine_schema, routine_name,
66
group_name, transform_type

Diff for: contrib/hstore_plperl/expected/hstore_plperlu.out

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
CREATE EXTENSION hstore;
2-
CREATE EXTENSION plperlu;
3-
CREATE EXTENSION hstore_plperlu;
1+
CREATE EXTENSION hstore_plperlu CASCADE;
2+
NOTICE: installing required extension "hstore"
3+
NOTICE: installing required extension "plperlu"
44
SELECT transforms.udt_schema, transforms.udt_name,
55
routine_schema, routine_name,
66
group_name, transform_type

Diff for: contrib/hstore_plperl/sql/hstore_plperl.sql

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
CREATE EXTENSION hstore;
2-
CREATE EXTENSION plperl;
3-
CREATE EXTENSION hstore_plperl;
1+
CREATE EXTENSION hstore_plperl CASCADE;
42

53
SELECT transforms.udt_schema, transforms.udt_name,
64
routine_schema, routine_name,

Diff for: contrib/hstore_plperl/sql/hstore_plperlu.sql

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
CREATE EXTENSION hstore;
2-
CREATE EXTENSION plperlu;
3-
CREATE EXTENSION hstore_plperlu;
1+
CREATE EXTENSION hstore_plperlu CASCADE;
42

53
SELECT transforms.udt_schema, transforms.udt_name,
64
routine_schema, routine_name,

Diff for: contrib/hstore_plpython/expected/hstore_plpython.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
CREATE EXTENSION plpython2u;
2-
CREATE EXTENSION hstore_plpython2u;
1+
CREATE EXTENSION hstore_plpython2u CASCADE;
2+
NOTICE: installing required extension "plpython2u"
33
-- test hstore -> python
44
CREATE FUNCTION test1(val hstore) RETURNS int
55
LANGUAGE plpythonu

Diff for: contrib/hstore_plpython/sql/hstore_plpython.sql

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
CREATE EXTENSION plpython2u;
2-
CREATE EXTENSION hstore_plpython2u;
1+
CREATE EXTENSION hstore_plpython2u CASCADE;
32

43

54
-- test hstore -> python

Diff for: contrib/ltree_plpython/expected/ltree_plpython.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
CREATE EXTENSION plpython2u;
2-
CREATE EXTENSION ltree_plpython2u;
1+
CREATE EXTENSION ltree_plpython2u CASCADE;
2+
NOTICE: installing required extension "plpython2u"
33
CREATE FUNCTION test1(val ltree) RETURNS int
44
LANGUAGE plpythonu
55
TRANSFORM FOR TYPE ltree

Diff for: contrib/ltree_plpython/sql/ltree_plpython.sql

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
CREATE EXTENSION plpython2u;
2-
CREATE EXTENSION ltree_plpython2u;
1+
CREATE EXTENSION ltree_plpython2u CASCADE;
32

43

54
CREATE FUNCTION test1(val ltree) RETURNS int

Diff for: doc/src/sgml/ref/create_extension.sgml

+42
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CREATE EXTENSION [ IF NOT EXISTS ] <replaceable class="parameter">extension_name
2525
[ WITH ] [ SCHEMA <replaceable class="parameter">schema_name</replaceable> ]
2626
[ VERSION <replaceable class="parameter">version</replaceable> ]
2727
[ FROM <replaceable class="parameter">old_version</replaceable> ]
28+
[ CASCADE ]
2829
</synopsis>
2930
</refsynopsisdiv>
3031

@@ -94,6 +95,35 @@ CREATE EXTENSION [ IF NOT EXISTS ] <replaceable class="parameter">extension_name
9495
If not specified, and the extension's control file does not specify a
9596
schema either, the current default object creation schema is used.
9697
</para>
98+
<para>
99+
If the extension specifies <literal>schema</> in its control file,
100+
the schema cannot be overriden with <literal>SCHEMA</> clause.
101+
The <literal>SCHEMA</> clause in this case works as follows:
102+
<itemizedlist>
103+
<listitem>
104+
<para>
105+
If <replaceable class="parameter">schema_name</replaceable> matches
106+
the schema in control file, it will be used normally as there is no
107+
conflict.
108+
</para>
109+
</listitem>
110+
<listitem>
111+
<para>
112+
If the <literal>CASCADE</> clause is given, the
113+
<replaceable class="parameter">schema_name</replaceable> will only
114+
be used for the missing required extensions which do not specify
115+
<literal>schema</> in their control files.
116+
</para>
117+
</listitem>
118+
<listitem>
119+
<para>
120+
If <replaceable class="parameter">schema_name</replaceable> is not
121+
the same as the one in extension's control file and the
122+
<literal>CASCADE</> clause is not given, error will be thrown.
123+
</para>
124+
</listitem>
125+
</itemizedlist>
126+
</para>
97127
<para>
98128
Remember that the extension itself is not considered to be within any
99129
schema: extensions have unqualified names that must be unique
@@ -139,6 +169,18 @@ CREATE EXTENSION [ IF NOT EXISTS ] <replaceable class="parameter">extension_name
139169
</para>
140170
</listitem>
141171
</varlistentry>
172+
173+
<varlistentry>
174+
<term><literal>CASCADE</></term>
175+
<listitem>
176+
<para>
177+
Try to install extension including the required dependencies
178+
recursively. The <literal>SCHEMA</> option will be propagated
179+
to the required extensions. Other options are not recursively
180+
applied when using this clause.
181+
</para>
182+
</listitem>
183+
</varlistentry>
142184
</variablelist>
143185
</refsect1>
144186

0 commit comments

Comments
 (0)