Skip to content

Commit f0924df

Browse files
committed
Can pass template at database creation
1 parent 73aac35 commit f0924df

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

manifests/server/database.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$dbname = $title,
44
$owner = $postgresql::server::user,
55
$tablespace = undef,
6+
$template = 'template0',
67
$encoding = $postgresql::server::encoding,
78
$locale = $postgresql::server::locale,
89
$istemplate = false
@@ -43,7 +44,7 @@
4344
default => "--tablespace='${tablespace}' ",
4445
}
4546

46-
$createdb_command = "${createdb_path} --owner='${owner}' --template=template0 ${encoding_option}${locale_option}${tablespace_option} '${dbname}'"
47+
$createdb_command = "${createdb_path} --owner='${owner}' --template=${template} ${encoding_option}${locale_option}${tablespace_option} '${dbname}'"
4748

4849
postgresql_psql { "Check for existence of db '${dbname}'":
4950
command => 'SELECT 1',

manifests/server/db.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
$locale = $postgresql::server::locale,
88
$grant = 'ALL',
99
$tablespace = undef,
10+
$template = 'template0',
1011
$istemplate = false,
1112
$owner = undef
1213
) {
1314
postgresql::server::database { $name:
1415
encoding => $encoding,
1516
tablespace => $tablespace,
17+
template => $template,
1618
locale => $locale,
1719
istemplate => $istemplate,
1820
owner => $owner,

spec/system/server/db_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,35 @@ class { 'postgresql::server': }
140140
end
141141
end
142142
end
143+
144+
it 'should take a template parameter' do
145+
begin
146+
pp = <<-EOS.unindent
147+
$db = 'postgresql_test_db'
148+
class { 'postgresql::server': }
149+
150+
postgresql::server::db { $db:
151+
user => $db,
152+
template => 'template1',
153+
password => postgresql_password($db, $db),
154+
}
155+
EOS
156+
157+
puppet_apply(pp) do |r|
158+
r.exit_code.should_not == 1
159+
r.refresh
160+
r.exit_code.should == 0
161+
end
162+
163+
psql('--command="select datname from pg_database" postgresql_test_db') do |r|
164+
r.stdout.should =~ /postgresql_test_db/
165+
r.stderr.should be_empty
166+
r.exit_code.should == 0
167+
end
168+
ensure
169+
psql('--command="drop database postgresql_test_db" postgres') do |r|
170+
r.exit_code.should == 0
171+
end
172+
end
173+
end
143174
end

0 commit comments

Comments
 (0)