Corrections: etc/nsd/zone.d/* - Champ SPF déprécié
[lhc/ateliers.git] / local / postgresql-database-create
1 #!/bin/sh -eux
2 db="$1"
3 owner="${2:-$db}"
4 case $(sudo -u postgres psql template1 -t -c \
5 "SELECT datname
6 FROM pg_catalog.pg_database
7 WHERE datname = '$db'
8 LIMIT 1"
9 ) in
10 (" $db") true;;
11 (*)
12 sudo -u postgres psql template1 -a -f - --set ON_ERROR_STOP=1 <<-EOF
13 CREATE DATABASE $db WITH OWNER=$owner;
14 EOF
15 ;;
16 esac
17 sudo -u postgres psql template1 -a -f - --set ON_ERROR_STOP=1 <<-EOF
18 REVOKE ALL ON DATABASE $db FROM public;
19 EOF
20 sudo -u postgres psql "$db" -a -f - --set ON_ERROR_STOP=1 <<-EOF
21 GRANT ALL ON SCHEMA public TO $owner WITH GRANT OPTION;
22 EOF