Ajout : roundcube.
[lhc/ateliers.git] / local / postgresql-schema-create
diff --git a/local/postgresql-schema-create b/local/postgresql-schema-create
new file mode 100755 (executable)
index 0000000..64ee80d
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh -eux
+db="$1"
+schema="${2:-$db}"
+owner="${3:-$schema}"
+sudo -u postgres psql "$db" -a -f - --set ON_ERROR_STOP=1 <<-EOF
+       DO LANGUAGE plpgsql \$\$
+       BEGIN
+               IF NOT EXISTS (
+                SELECT *
+                FROM pg_catalog.pg_namespace
+                WHERE nspname = '$schema'
+                LIMIT 1
+               ) THEN
+                       CREATE SCHEMA $schema
+                        AUTHORIZATION $owner;
+               END IF;
+       END;
+       \$\$;
+       EOF