Skip to content
Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ For example, to create a database called `test1` with a corresponding user of th
####`namevar`
The namevar for the resource designates the name of the database.

####`comment`
A comment to be stored about the database using the PostgreSQL COMMENT command.

####`dbname`
The name of the database to be created. Defaults to `namevar`.

Expand Down
8 changes: 8 additions & 0 deletions manifests/server/database.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Define for creating a database. See README.md for more details.
define postgresql::server::database(
$comment = undef,
$dbname = $title,
$owner = $postgresql::server::user,
$tablespace = undef,
Expand Down Expand Up @@ -76,6 +77,13 @@
db => $default_db,
}

if $comment {
Exec[ $createdb_command ]->
postgresql_psql {"COMMENT ON DATABASE ${dbname} IS '${comment}'":
unless => "SELECT pg_catalog.shobj_description(d.oid, 'pg_database') as \"Description\" FROM pg_catalog.pg_database d WHERE datname = '${dbname}' AND pg_catalog.shobj_description(d.oid, 'pg_database') = '${comment}'",
}
}

# Build up dependencies on tablespace
if($tablespace != undef and defined(Postgresql::Server::Tablespace[$tablespace])) {
Postgresql::Server::Tablespace[$tablespace]->Exec[$createdb_command]
Expand Down
2 changes: 2 additions & 0 deletions manifests/server/db.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
define postgresql::server::db (
$user,
$password,
$comment = undef,
$dbname = $title,
$encoding = $postgresql::server::encoding,
$locale = $postgresql::server::locale,
Expand All @@ -15,6 +16,7 @@

if ! defined(Postgresql::Server::Database[$dbname]) {
postgresql::server::database { $dbname:
comment => $comment,
encoding => $encoding,
tablespace => $tablespace,
template => $template,
Expand Down
5 changes: 5 additions & 0 deletions spec/acceptance/db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class { 'postgresql::server': }
location => '#{tmpdir}',
} ->
postgresql::server::db { 'postgresql_test_db':
comment => 'testcomment',
user => 'test',
password => 'test1',
tablespace => 'postgresql_test_db',
Expand All @@ -27,6 +28,10 @@ class { 'postgresql::server': }
psql('--command="SELECT 1 FROM pg_roles WHERE rolname=\'test\'"') do |r|
expect(r.stdout).to match(/\(1 row\)/)
end

psql('--command="SELECT pg_catalog.shobj_description(d.oid, \'pg_database\') FROM pg_catalog.pg_database d WHERE datname = \'postgresql_test_db\' AND pg_catalog.shobj_description(d.oid, \'pg_database\') = \'testcomment\'"') do |r|
expect(r.stdout).to match(/\(1 row\)/)
end
ensure
psql('--command="drop database postgresql_test_db" postgres')
psql('--command="DROP USER test"')
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/defines/server/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@

it { is_expected.to contain_postgresql__server__database('test') }
it { is_expected.to contain_postgresql_psql("Check for existence of db 'test'") }

context "with comment set to 'test comment'" do
let (:params) {{ :comment => 'test comment' }}

it { is_expected.to contain_postgresql_psql("COMMENT ON DATABASE test IS 'test comment'") }
end
end