Specifying encoding on database creation
[hcoop/domtool2.git] / src / plugins / domtool-postgres
... / ...
CommitLineData
1#!/bin/sh -e
2
3case $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 ENCODING=$4
15 DBNAME="${USERNAME}_${DBNAME_BASE}"
16
17 if [ -n $ENCODING ]; then
18 ENCODING="-E $ENCODING"
19 fi
20
21 sudo -u postgres createdb -O $USERNAME -D user_$USERNAME $ENCODING $DBNAME
22 ;;
23
24 dropdb)
25 USERNAME=$2
26 DBNAME_BASE=$3
27 DBNAME="${USERNAME}_${DBNAME_BASE}"
28
29 sudo -u postgres dropdb $DBNAME
30 ;;
31
32 *)
33 echo "Usage: domtool-postgres [adduser <user> | createdb <user> <db> | dropdb <user> <db>]"
34 ;;
35esac