]> git.openstreetmap.org Git - chef.git/commitdiff
Create postgres databases from template0 and set the collation and ctype
authorTom Hughes <tom@compton.nu>
Tue, 4 Jun 2013 12:55:31 +0000 (13:55 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 4 Jun 2013 12:56:38 +0000 (13:56 +0100)
cookbooks/postgresql/libraries/postgresql.rb
cookbooks/postgresql/providers/database.rb
cookbooks/postgresql/resources/database.rb

index bd10a0233151b8ce4a32c5cb2e14e77a97d983ff..2f672960ccdfe25ad691340fbcb9fdd66f152ab0 100644 (file)
@@ -75,10 +75,12 @@ class Chef
     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
index eee79031d4004297c050fb9ba5563a2a5c9c534d..9cf9dd4421dce04ada41d0103ee072e322162ad1 100644 (file)
@@ -26,13 +26,15 @@ def load_current_resource
   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
index 039c12467c7fb86635ddaf8a3475e5aa7309d01d..1a63f3ac889fa8a6a8e8fba5cfeb26e23998f554 100644 (file)
@@ -23,6 +23,8 @@ attribute :database, :kind_of => String, :name_attribute => true
 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