Specifying encoding on database creation
[hcoop/domtool2.git] / src / plugins / domtool-postgres
index 1d945d4..214e9ac 100755 (executable)
@@ -7,14 +7,29 @@ case $1 in
                sudo -u postgres psql -c "CREATE USER $USERNAME" template1
                sudo -u postgres psql -c "ALTER TABLESPACE user_$USERNAME OWNER TO $USERNAME"
        ;;
+
        createdb)
                USERNAME=$2
                DBNAME_BASE=$3
+               ENCODING=$4
                DBNAME="${USERNAME}_${DBNAME_BASE}"
 
-               sudo -u postgres createdb -O $USERNAME -D user_$USERNAME $DBNAME
+               if [ -n $ENCODING ]; then
+                   ENCODING="-E $ENCODING"
+               fi
+
+               sudo -u postgres createdb -O $USERNAME -D user_$USERNAME $ENCODING $DBNAME
        ;;
+
+       dropdb)
+               USERNAME=$2
+               DBNAME_BASE=$3
+               DBNAME="${USERNAME}_${DBNAME_BASE}"
+
+               sudo -u postgres dropdb $DBNAME
+       ;;
+
        *)
-               echo "Usage: domtool-postgres [adduser <user> | createdb <user> <table>]"
+               echo "Usage: domtool-postgres [adduser <user> | createdb <user> <db> | dropdb <user> <db>]"
        ;;
 esac