Skip to content

Commit

Permalink
Fix comment detection
Browse files Browse the repository at this point in the history
On psql 8.1, `pg_catalog.shobj_description` does not exist. Also, if the
database to comment is not the current db then this warning will be
raised and the comment will not be applied: `WARNING:  database comments
may only be applied to the current database`

This fix uses the pg_* databases to find the comment based on the
database oid rather than the shared object description function.
  • Loading branch information
hunner committed Feb 5, 2015
1 parent 6d2b66c commit f889a46
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 f889a46

Please sign in to comment.