case $1 in
adduser)
- echo "I would create PostgreSQL user $2."
+ USERNAME=$2
+
+ sudo -u postgres psql -c "CREATE USER $USERNAME" template1
+ sudo -u postgres psql -c "ALTER TABLESPACE user_$USERNAME OWNER TO $USERNAME"
;;
createdb)
- echo "I would create PostgreSQL table $2_$3 for user $2."
+ USERNAME=$2
+ DBNAME_BASE=$3
+ DBNAME="${USERNAME}_${DBNAME_BASE}"
+
+ sudo -u postgres createdb -O $USERNAME -D user_$USERNAME $DBNAME
;;
*)
echo "Usage: domtool-postgres [adduser <user> | createdb <user> <table>]"