end
def databases
- @databases ||= query("SELECT d.datname, u.usename, d.encoding FROM pg_database AS d INNER JOIN pg_user AS u ON d.datdba = u.usesysid").inject({}) do |databases,database|
+ @databases ||= query("SELECT d.datname, u.usename, d.encoding, d.datcollate, d.datctype FROM pg_database AS d INNER JOIN pg_user AS u ON d.datdba = u.usesysid").inject({}) do |databases,database|
databases[database[:datname]] = {
:owner => database[:usename],
- :encoding => database[:encoding]
+ :encoding => database[:encoding],
+ :collate => database[:datcollate],
+ :ctype => database[:datctype]
}
databases
end
if pg_database = @pg.databases[@current_resource.database]
@current_resource.owner(pg_database[:owner])
@current_resource.encoding(pg_database[:encoding])
+ @current_resource.encoding(pg_database[:collate])
+ @current_resource.encoding(pg_database[:ctype])
end
@current_resource
end
action :create do
unless @pg.databases.include?(new_resource.database)
- @pg.execute(:command => "CREATE DATABASE #{new_resource.database} OWNER #{new_resource.owner} ENCODING '#{new_resource.encoding}'")
+ @pg.execute(:command => "CREATE DATABASE #{new_resource.database} OWNER #{new_resource.owner} TEMPLATE template0 ENCODING '#{new_resource.encoding}' LC_COLLATE '#{new_resource.collation}' LC_CTYPE '#{new_resource.ctype}'")
new_resource.updated_by_last_action(true)
else
if new_resource.owner != @current_resource.owner
attribute :cluster, :kind_of => String, :required => true
attribute :owner, :kind_of => String, :required => true
attribute :encoding, :kind_of => String, :default => "UTF8"
+attribute :collation, :kind_of => String, :default => "en_GB.UTF8"
+attribute :ctype, :kind_of => String, :default => "en_GB.UTF8"
def initialize(*args)
super