Merge pull request #204 from mcanevet/set_istemplate
Add support for istemplate parameter where creating db
This commit is contained in:
commit
847f54ce6c
4 changed files with 93 additions and 11 deletions
|
@ -325,6 +325,9 @@ Override the locale during creation of the database. Defaults to the default def
|
||||||
####`grant`
|
####`grant`
|
||||||
Grant permissions during creation. Defaults to `ALL`.
|
Grant permissions during creation. Defaults to `ALL`.
|
||||||
|
|
||||||
|
####`istemplate`
|
||||||
|
Define database as a template. Defaults to `false`.
|
||||||
|
|
||||||
###Resource: postgresql::database
|
###Resource: postgresql::database
|
||||||
This defined type can be used to create a database with no users and no permissions, which is a rare use case.
|
This defined type can be used to create a database with no users and no permissions, which is a rare use case.
|
||||||
|
|
||||||
|
@ -343,6 +346,9 @@ Override the character set during creation of the database. Defaults to the defa
|
||||||
####`locale`
|
####`locale`
|
||||||
Override the locale during creation of the database. Defaults to the default defined during installation.
|
Override the locale during creation of the database. Defaults to the default defined during installation.
|
||||||
|
|
||||||
|
####`istemplate`
|
||||||
|
Define database as a template. Defaults to `false`.
|
||||||
|
|
||||||
###Resource: postgresql::database\_grant
|
###Resource: postgresql::database\_grant
|
||||||
This defined type manages grant based access privileges for users. Consult the PostgreSQL documentation for `grant` for more information.
|
This defined type manages grant based access privileges for users. Consult the PostgreSQL documentation for `grant` for more information.
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ define postgresql::database(
|
||||||
$owner = $postgresql::params::user,
|
$owner = $postgresql::params::user,
|
||||||
$tablespace = undef,
|
$tablespace = undef,
|
||||||
$charset = $postgresql::params::charset,
|
$charset = $postgresql::params::charset,
|
||||||
$locale = $postgresql::params::locale
|
$locale = $postgresql::params::locale,
|
||||||
|
$istemplate = false
|
||||||
) {
|
) {
|
||||||
include postgresql::params
|
include postgresql::params
|
||||||
|
|
||||||
|
@ -76,4 +77,9 @@ define postgresql::database(
|
||||||
refreshonly => true,
|
refreshonly => true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Exec [ $createdb_command ] ->
|
||||||
|
|
||||||
|
postgresql_psql {"UPDATE pg_database SET datistemplate = ${istemplate} WHERE datname = '${dbname}'":
|
||||||
|
unless => "SELECT datname FROM pg_database WHERE datname = '${dbname}' AND datistemplate = ${istemplate}",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,8 @@ define postgresql::db (
|
||||||
$charset = $postgresql::params::charset,
|
$charset = $postgresql::params::charset,
|
||||||
$locale = $postgresql::params::locale,
|
$locale = $postgresql::params::locale,
|
||||||
$grant = 'ALL',
|
$grant = 'ALL',
|
||||||
$tablespace = undef
|
$tablespace = undef,
|
||||||
|
$istemplate = false
|
||||||
) {
|
) {
|
||||||
include postgresql::params
|
include postgresql::params
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ define postgresql::db (
|
||||||
#provider => 'postgresql',
|
#provider => 'postgresql',
|
||||||
require => Class['postgresql::server'],
|
require => Class['postgresql::server'],
|
||||||
locale => $locale,
|
locale => $locale,
|
||||||
|
istemplate => $istemplate,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! defined(Postgresql::Database_user[$user]) {
|
if ! defined(Postgresql::Database_user[$user]) {
|
||||||
|
|
|
@ -95,6 +95,74 @@ describe 'install:' do
|
||||||
psql('--command="drop database test1" postgres')
|
psql('--command="drop database test1" postgres')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should take an istemplate parameter' do
|
||||||
|
begin
|
||||||
|
pp = <<-EOS
|
||||||
|
$db = 'template2'
|
||||||
|
include postgresql::server
|
||||||
|
|
||||||
|
postgresql::db { $db:
|
||||||
|
user => $db,
|
||||||
|
password => postgresql_password($db, $db),
|
||||||
|
istemplate => true,
|
||||||
|
}
|
||||||
|
EOS
|
||||||
|
|
||||||
|
puppet_apply(pp) do |r|
|
||||||
|
r.exit_code.should_not == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
puppet_apply(pp) do |r|
|
||||||
|
r.exit_code.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
psql('--command="select datname from pg_database" template2') do |r|
|
||||||
|
r.stdout.should =~ /template2/
|
||||||
|
r.stderr.should be_empty
|
||||||
|
r.exit_code.should == 0
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
psql('--command="drop database template2" postgres') do |r|
|
||||||
|
r.stdout.should be_empty
|
||||||
|
r.stderr.should =~ /cannot drop a template database/
|
||||||
|
r.exit_code.should_not == 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should update istemplate parameter' do
|
||||||
|
begin
|
||||||
|
pp = <<-EOS
|
||||||
|
$db = 'template2'
|
||||||
|
include postgresql::server
|
||||||
|
|
||||||
|
postgresql::db { $db:
|
||||||
|
user => $db,
|
||||||
|
password => postgresql_password($db, $db),
|
||||||
|
istemplate => false,
|
||||||
|
}
|
||||||
|
EOS
|
||||||
|
|
||||||
|
puppet_apply(pp) do |r|
|
||||||
|
r.exit_code.should_not == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
puppet_apply(pp) do |r|
|
||||||
|
r.exit_code.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
psql('--command="select datname from pg_database" template2') do |r|
|
||||||
|
r.stdout.should =~ /template2/
|
||||||
|
r.stderr.should be_empty
|
||||||
|
r.exit_code.should == 0
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
psql('--command="drop database template2" postgres') do |r|
|
||||||
|
r.exit_code.should == 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'postgresql::psql' do
|
describe 'postgresql::psql' do
|
||||||
|
|
Loading…
Reference in a new issue