Skip to content

Commit

Permalink
Merge pull request #559 from hunner/fix_dbcomment
Browse files Browse the repository at this point in the history
Fix comment detection
  • Loading branch information
Morgan Haskel committed Feb 6, 2015
2 parents 6d2b66c + f889a46 commit fdc8180
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 7 additions & 2 deletions manifests/server/database.pp
Expand Up @@ -78,10 +78,15 @@
}

if $comment {
# The shobj_description function was only introduced with 8.2
$comment_information_function = $version ? {
'8.1' => 'obj_description',
default => 'shobj_description',
}
Exec[ $createdb_command ]->
postgresql_psql {"COMMENT ON DATABASE ${dbname} IS '${comment}'":
unless => "SELECT description FROM pg_description JOIN pg_database ON objoid = pg_database.oid WHERE datname = '${dbname}' AND description = '${comment}'",
db => $dbname,
unless => "SELECT pg_catalog.${comment_information_function}(d.oid, 'pg_database') as \"Description\" FROM pg_catalog.pg_database d WHERE datname = '${dbname}' AND pg_catalog.${comment_information_function}(d.oid, 'pg_database') = '${comment}'",
db => $dbname,
}
}

Expand Down
9 changes: 8 additions & 1 deletion spec/acceptance/db_spec.rb
Expand Up @@ -29,7 +29,14 @@ class { 'postgresql::server': }
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|
result = shell('psql --version')
version = result.stdout.match(%r{\s(8\.\d)})[1]
if version > "8.1"
comment_information_function = "shobj_description"
else
comment_information_function = "obj_description"
end
psql("--dbname postgresql_test_db --command=\"SELECT pg_catalog.#{comment_information_function}(d.oid, 'pg_database') FROM pg_catalog.pg_database d WHERE datname = 'postgresql_test_db' AND pg_catalog.#{comment_information_function}(d.oid, 'pg_database') = 'testcomment'\"") do |r|
expect(r.stdout).to match(/\(1 row\)/)
end
ensure
Expand Down

0 comments on commit fdc8180

Please sign in to comment.