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.
11921192
11931193Specifies the database on which to activate the extension.
11941194
1195+ ##### ` schema `
1196+
1197+ Specifies the schema on which to activate the extension.
1198+
11951199##### ` ensure `
11961200
11971201Specifies whether to activate or deactivate the extension.
Original file line number Diff line number Diff line change 22define postgresql::server::extension (
33 $database ,
44 $extension = $name,
5+ Optional[String[1]] $schema = undef ,
56 Optional[String[1]] $version = undef ,
67 String[1] $ensure = ' present' ,
78 $package_name = undef ,
5152 unless => " SELECT 1 WHERE ${unless_mod} EXISTS (SELECT 1 FROM pg_extension WHERE extname = '${extension} ')" ,
5253 }
5354
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+
5482 if $package_name {
5583 $_package_ensure = $package_ensure ? {
5684 undef => $ensure ,
Original file line number Diff line number Diff line change 3434 }
3535 end
3636
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+
3747 context "when setting package name" do
3848 let ( :params ) { super ( ) . merge ( {
3949 :package_name => 'postgis' ,
You can’t perform that action at this time.
0 commit comments