Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions manifests/server/extension.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
# Specifies the version of the extension which the database uses. When an extension package is updated, this does not automatically
# change the effective version in each database.
# This needs be updated using the PostgreSQL-specific SQL ALTER EXTENSION...
# version may be set to latest, in which case the SQL ALTER EXTENSION "extension" UPDATE is applied to this database (only).
# When the extension is being created (ensure is 'present') and version is set to a specific version, the extension is created using
# CREATE EXTENSION "extension" VERSION 'version'. eg. If extension is set to postgis and version is set to 3.3, this will apply the SQL
# CREATE EXTENSION "postgis" VERSION '3.3'.
# version may be set to latest, in which case an extension being created uses no explicit VERSION clause, and, once created, the SQL
# ALTER EXTENSION "extension" UPDATE is applied to this database (only).
# version may be set to a specific version, in which case the extension is updated using ALTER EXTENSION "extension" UPDATE TO 'version'
# eg. If extension is set to postgis and version is set to 2.3.3, this will apply the SQL ALTER EXTENSION "postgis" UPDATE TO '2.3.3' to
# this database only.
# version may be omitted, in which case no ALTER EXTENSION... SQL is applied, and the version will be left unchanged.
# version may be omitted, in which case no version-specific SQL is applied, and the version will be left unchanged.
#
# @param ensure Specifies whether to activate or deactivate the extension. Valid options: 'present' or 'absent'.
# @param package_name Specifies a package to install prior to activating the extension.
Expand Down Expand Up @@ -54,7 +58,7 @@

case $ensure {
'present': {
$command = "CREATE EXTENSION \"${extension}\""
$command = inline_epp('<%- | String $extension, Optional[String] $version | -%>CREATE EXTENSION "<%= $extension %>"<% if $version and $version != "latest" { %> VERSION "<%= $version %>"<% } %>', { extension => $extension, version => $version })
$unless_mod = undef
$psql_cmd_require = $package_name ? {
undef => $default_psql_require,
Expand Down
22 changes: 22 additions & 0 deletions spec/defines/server/extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@
}
end

context 'when created with a specific version' do
let(:params) do
super().merge(version: '3.5.7')
end

it {
expect(subject).to contain_postgresql_psql('template_postgis: CREATE EXTENSION "postgis" VERSION "3.5.7"')
.with(db: 'template_postgis', command: 'CREATE EXTENSION "postgis" VERSION "3.5.7"').that_requires('Postgresql::Server::Database[template_postgis]')
}
end

context 'when created with version latest' do
let(:params) do
super().merge(version: 'latest')
end

it {
expect(subject).to contain_postgresql_psql('template_postgis: CREATE EXTENSION "postgis"')
.with(db: 'template_postgis', command: 'CREATE EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]')
}
end

context 'when schema is specified' do
let(:params) do
super().merge(schema: 'pg_catalog')
Expand Down