Database scripts altered to support drop
[hcoop/domtool2.git] / src / plugins / domtool-postgres
1 #!/bin/sh -e
2
3 case $1 in
4 adduser)
5 USERNAME=$2
6
7 sudo -u postgres psql -c "CREATE USER $USERNAME" template1
8 sudo -u postgres psql -c "ALTER TABLESPACE user_$USERNAME OWNER TO $USERNAME"
9 ;;
10
11 createdb)
12 USERNAME=$2
13 DBNAME_BASE=$3
14 DBNAME="${USERNAME}_${DBNAME_BASE}"
15
16 sudo -u postgres createdb -O $USERNAME -D user_$USERNAME $DBNAME
17 ;;
18
19 dropdb)
20 USERNAME=$2
21 DBNAME_BASE=$3
22 DBNAME="${USERNAME}_${DBNAME_BASE}"
23
24 sudo -u postgres dropdb $DBNAME
25 ;;
26
27 *)
28 echo "Usage: domtool-postgres [adduser <user> | createdb <user> <db> | dropdb <user> <db>]"
29 ;;
30 esac