X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=local%2Fpostgresql-schema-create;fp=local%2Fpostgresql-schema-create;h=64ee80d329ce6e4b370784003741bcd44a721462;hb=b75d4503ef9c919231c0c02daf5a1ed1e57c73af;hp=0000000000000000000000000000000000000000;hpb=4c57b350e0265cfadb9bbf95cd55ae491ee66820;p=lhc%2Fateliers.git diff --git a/local/postgresql-schema-create b/local/postgresql-schema-create new file mode 100755 index 0000000..64ee80d --- /dev/null +++ b/local/postgresql-schema-create @@ -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