Permalink
Browse files

Merge pull request #7 from finnlabs/COOK-1401

COOK-1401 - Allow to set the collation for new Postgres and MySQL DBs
  • Loading branch information...
jtimberman committed Jul 24, 2012
2 parents 124ebd7 + ca088ad commit e0cee214104c6c32667eb9a58ecf2f18d63ca295
@@ -36,7 +36,11 @@ def action_create
unless exists?
begin
Chef::Log.debug("#{@new_resource}: Creating database #{new_resource.database_name}")
- db.query("create database #{new_resource.database_name}")
+ create_sql = "CREATE DATABASE #{new_resource.database_name}"
+ create_sql += " CHARACTER SET = #{new_resource.encoding}" if new_resource.encoding
+ create_sql += " COLLATE = #{new_resource.collation}" if new_resource.collation
+ Chef::Log.debug("#{@new_resource}: Performing query [#{create_sql}]")
+ db.query(create_sql)
@new_resource.updated_by_last_action(true)
ensure
close
@@ -45,6 +45,7 @@ def action_create
create_sql += " TEMPLATE = #{new_resource.template}" if new_resource.template
create_sql += " ENCODING = #{encoding}" if new_resource.encoding
create_sql += " TABLESPACE = #{new_resource.tablespace}" if new_resource.tablespace
+ create_sql += " LC_CTYPE = '#{new_resource.collation}' LC_COLLATE = '#{new_resource.collation}'" if new_resource.collation
create_sql += " CONNECTION LIMIT = #{new_resource.connection_limit}" if new_resource.connection_limit
create_sql += " OWNER = #{new_resource.owner}" if new_resource.owner
Chef::Log.debug("#{@new_resource}: Performing query [#{create_sql}]")
@@ -72,6 +72,14 @@ def template(arg=nil)
)
end
+ def collation(arg=nil)
+ set_or_return(
+ :collation,
+ arg,
+ :kind_of => String
+ )
+ end
+
def encoding(arg=nil)
set_or_return(
:encoding,

0 comments on commit e0cee21

Please sign in to comment.