Files
zulip/tools/postgres-init-db
Jason Michalski 14c0f3def9 Fix the path in postgres-init-db to get-django-setting
postgres-init-db was expecting to be located two directories below the
project root. It is only one directory below the root of the project so
remove a set of .. .

(imported from commit 228b47ac2539caf2b6cd12a1b5f399534cf0c866)
2014-01-07 10:24:04 -05:00

51 lines
1.1 KiB
Plaintext
Executable File

#/bin/sh -xe
ROOT_POSTGRES="sudo -u postgres psql"
DEFAULT_DB=""
if [ "$(uname)" = "Darwin" ]; then
ROOT_POSTGRES="psql"
DEFAULT_DB="postgres"
fi
if [[ $# == 0 ]]; then
USERNAME=zulip
PASSWORD=$($(dirname $0)/../bin/get-django-setting LOCAL_DATABASE_PASSWORD)
DBNAME=zulip
SEARCH_PATH="$USERNAME",public
elif [[ $# == 4 ]]; then
USERNAME=$1
PASSWORD=$2
DBNAME=$3
SEARCH_PATH=$4
else
echo "Usage Instructions"
echo "Run with either no arguments (sets up devel db for local deploy--zulip with user zulip)"
echo "or specify <db-username> <password> <db-name> <user-schema-search-path>"
exit
fi
$ROOT_POSTGRES $DEFAULT_DB << EOF
CREATE USER $USERNAME WITH PASSWORD '$PASSWORD';
ALTER USER $USERNAME CREATEDB;
ALTER ROLE $USERNAME SET search_path TO $SEARCH_PATH;
EOF
umask go-rw
echo "*:*:*:$USERNAME:$PASSWORD" >> ~/.pgpass
chmod go-rw ~/.pgpass
psql -h localhost postgres $USERNAME <<EOF
DROP DATABASE IF EXISTS $DBNAME;
CREATE DATABASE $DBNAME;
EOF
DEFAULT_DB=$DBNAME
$ROOT_POSTGRES $DEFAULT_DB << EOF
DROP SCHEMA public CASCADE;
EOF
echo "Database created"