File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1192,6 +1192,10 @@ Manages a PostgreSQL extension.
1192
1192
1193
1193
Specifies the database on which to activate the extension.
1194
1194
1195
+ ##### ` schema `
1196
+
1197
+ Specifies the schema on which to activate the extension.
1198
+
1195
1199
##### ` ensure `
1196
1200
1197
1201
Specifies whether to activate or deactivate the extension.
Original file line number Diff line number Diff line change 2
2
define postgresql::server::extension (
3
3
$database ,
4
4
$extension = $name,
5
+ Optional[String[1]] $schema = undef ,
5
6
Optional[String[1]] $version = undef ,
6
7
String[1] $ensure = ' present' ,
7
8
$package_name = undef ,
51
52
unless => " SELECT 1 WHERE ${unless_mod} EXISTS (SELECT 1 FROM pg_extension WHERE extname = '${extension} ')" ,
52
53
}
53
54
55
+ if $ensure == ' present' and $schema {
56
+ $set_schema_command = " ALTER EXTENSION \" ${extension} \" SET SCHEMA \" ${schema} \" "
57
+
58
+ postgresql_psql { "${database}: ${set_schema_command}" :
59
+ command => $set_schema_command ,
60
+ unless => @(" END" )
61
+ SELECT 1
62
+ WHERE EXISTS (
63
+ SELECT 1
64
+ FROM pg_extension e
65
+ JOIN pg_namespace n ON e.extnamespace = n.oid
66
+ WHERE e.extname = ' ${extension}' AND
67
+ n.nspname = ' ${schema}'
68
+ )
69
+ |-END
70
+ ,
71
+ psql_user => $user ,
72
+ psql_group => $group ,
73
+ psql_path => $psql_path ,
74
+ connect_settings => $connect_settings ,
75
+ db => $database ,
76
+ require => Postgresql_psql[" ${database} : ${command} " ],
77
+ }
78
+
79
+ Postgresql::Server::Schema <| db == $database and schema == $schema |> -> Postgresql_psql[" ${database} : ${set_schema_command} " ]
80
+ }
81
+
54
82
if $package_name {
55
83
$_package_ensure = $package_ensure ? {
56
84
undef => $ensure ,
Original file line number Diff line number Diff line change 34
34
}
35
35
end
36
36
37
+ context "when schema is specified" do
38
+ let ( :params ) { super ( ) . merge ( {
39
+ :schema => 'pg_catalog' ,
40
+ } ) }
41
+
42
+ it {
43
+ is_expected . to contain_postgresql_psql ( 'template_postgis: ALTER EXTENSION "postgis" SET SCHEMA "pg_catalog"' )
44
+ }
45
+ end
46
+
37
47
context "when setting package name" do
38
48
let ( :params ) { super ( ) . merge ( {
39
49
:package_name => 'postgis' ,
You can’t perform that action at this time.
0 commit comments