Skip to content
This repository has been archived by the owner on Apr 7, 2018. It is now read-only.

Commit

Permalink
Merge pull request #7 from finnlabs/COOK-1401
Browse files Browse the repository at this point in the history
COOK-1401 - Allow to set the collation for new Postgres and MySQL DBs
  • Loading branch information
Joshua Timberman committed Jul 24, 2012
2 parents 124ebd7 + ca088ad commit e0cee21
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libraries/provider_database_mysql.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libraries/provider_database_postgresql.rb
Expand Up @@ -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}]")
Expand Down
8 changes: 8 additions & 0 deletions libraries/resource_database.rb
Expand Up @@ -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,
Expand Down

0 comments on commit e0cee21

Please sign in to comment.