Browse files

COOK-975: Change arg='DEFAULT' to arg=nil, :default => 'DEFAULT'

Setting arg='DEFAULT' won't pick up attribute arguments from the
recipe. This allows a user to set different template, tablespace,
connection limit and encoding in the recipe.
Also quote the encoding if it isn't DEFAULT.
  • Loading branch information...
1 parent 7312252 commit 73029378b235898e6b2301ce9450867d3c179df2 Ian Delahorne committed with jtimberman Jan 12, 2012
Showing with 17 additions and 9 deletions.
  1. +5 −1 libraries/provider_database_postgresql.rb
  2. +12 −8 libraries/resource_database.rb
View
6 libraries/provider_database_postgresql.rb
@@ -36,10 +36,14 @@ def load_current_resource
def action_create
unless exists?
begin
+ encoding = @new_resource.encoding
+ if encoding != "DEFAULT"
+ encoding = "'#{@new_resource.encoding}'"
+ end
Chef::Log.debug("#{@new_resource}: Creating database #{new_resource.database_name}")
create_sql = "CREATE DATABASE #{new_resource.database_name}"
create_sql += " TEMPLATE = #{new_resource.template}" if new_resource.template
- create_sql += " ENCODING = #{new_resource.encoding}" if new_resource.encoding
+ create_sql += " ENCODING = #{encoding}" if new_resource.encoding
create_sql += " TABLESPACE = #{new_resource.tablespace}" if new_resource.tablespace
create_sql += " CONNECTION LIMIT = #{new_resource.connection_limit}" if new_resource.connection_limit
create_sql += " OWNER = #{new_resource.owner}" if new_resource.owner
View
20 libraries/resource_database.rb
@@ -63,35 +63,39 @@ def sql(arg=nil)
end
#
- def template(arg='DEFAULT')
+ def template(arg=nil)
set_or_return(
:template,
arg,
- :kind_of => String
+ :kind_of => String,
+ :default => 'DEFAULT'
)
end
- def encoding(arg='DEFAULT')
+ def encoding(arg=nil)
set_or_return(
:encoding,
arg,
- :kind_of => String
+ :kind_of => String,
+ :default => 'DEFAULT'
)
end
- def tablespace(arg='DEFAULT')
+ def tablespace(arg=nil)
set_or_return(
:tablespace,
arg,
- :kind_of => String
+ :kind_of => String,
+ :default => 'DEFAULT'
)
end
- def connection_limit(arg='-1')
+ def connection_limit(arg=nil)
set_or_return(
:connection_limit,
arg,
- :kind_of => String
+ :kind_of => String,
+ :default => '-1'
)
end

0 comments on commit 7302937

Please sign in to comment.