Skip to content

Commit 34fc7a7

Browse files
committed
Allow empty string value for config entries
PostgreSQL supports and allows config entries, such as those in postgresql.conf, to be set to the empty string. The `postgresql::server::config_entry` defined type, however, requires String[1] when supplying string values. This doesn't allow for the empty string. This change relaxes the allowed data types for the `value` parameter of `postgresql::server::config_entry` to `String` from `String[1]` and adds a spec test to support the change. Fixes #1602
1 parent d5911ec commit 34fc7a7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

manifests/server/config_entry.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
define postgresql::server::config_entry (
1111
Enum['present', 'absent'] $ensure = 'present',
1212
String[1] $key = $name,
13-
Optional[Variant[String[1], Numeric, Array[String[1]]]] $value = undef,
13+
Optional[Variant[String, Numeric, Array[String[1]]]] $value = undef,
1414
Stdlib::Absolutepath $path = $postgresql::server::postgresql_conf_path,
1515
Optional[String[1]] $comment = undef,
1616
String[1] $instance_name = 'main',

spec/defines/server/config_entry_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,19 @@
7979
.that_notifies('Postgresql::Server::Instance::Service[main]')
8080
end
8181
end
82+
83+
# Example use case for empty values: using transaction-bound session
84+
# variables, like `SET LOCAL awesome_app.tenant_id = 92834` requires the
85+
# variable to be defined in postgresql.conf and initialised with a default
86+
# value (at least for PostgreSQL 13 and older, possibly also in newer
87+
# versions). The default value can, and sometimes, depending on the
88+
# application, should, be empty.
89+
context 'set a config entry value to the empty string' do
90+
let(:params) { { ensure: 'present', name: 'mydatabase.app_specific_parameter', value: '' } }
91+
92+
it 'sets value to the empty string' do
93+
expect(subject).to contain_postgresql_conf('mydatabase.app_specific_parameter').with(name: 'mydatabase.app_specific_parameter',
94+
value: '')
95+
end
96+
end
8297
end

0 commit comments

Comments
 (0)