Specifying encoding on database creation
[hcoop/domtool2.git] / src / plugins / postgres.sml
index 1689840..6465377 100644 (file)
 structure Postgres :> POSTGRES = struct
 
 fun adduser {user, passwd} =
 structure Postgres :> POSTGRES = struct
 
 fun adduser {user, passwd} =
-    if Slave.shell [Config.Postgres.adduser, user] then
-       NONE
-    else
-       SOME "Error executing CREATE USER script"
+    Option.map (fn s => "Error executing CREATE USER script:\n" ^ s)
+              (Slave.shellOutput [Config.Postgres.adduser, user])
 
 fun passwd _ = SOME "We don't use PostgreSQL passwords."
 
 
 fun passwd _ = SOME "We don't use PostgreSQL passwords."
 
-fun createdb {user, dbname} =
-    if Slave.shell [Config.Postgres.createdb, user, " ", dbname] then
-       NONE
-    else
-       SOME "Error executing CREATE DATABASE script"
+fun createdb {user, dbname, encoding} =
+    Option.map (fn s => "Error executing CREATE DATABASE script:\n" ^ s)
+              (Slave.shellOutput [Config.Postgres.createdb,
+                                  " ", user, " ", dbname,
+                                  case encoding of NONE => "" | SOME e => " " ^ e])
+
+fun dropdb {user, dbname} =
+    Option.map (fn s => "Error executing DROP DATABASE script:\n" ^ s)
+              (Slave.shellOutput [Config.Postgres.dropdb, user, " ", dbname])
 
 val _ = Dbms.register ("postgres", {getpass = NONE,
                                    adduser = adduser,
                                    passwd = passwd,
 
 val _ = Dbms.register ("postgres", {getpass = NONE,
                                    adduser = adduser,
                                    passwd = passwd,
-                                   createdb = createdb})
+                                   createdb = createdb,
+                                   dropdb = dropdb,
+                                   grant = fn _ => SOME "You don't need to use GRANT for Postgres."})
 
 end
 
 end