mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
The production database has a public schema. I thought we had dropped it, but apparently not. We should match what exists in prod either way. (imported from commit 1bf956360029ebbd59afc3cc30fca9a859343adf)
62 lines
1.4 KiB
Bash
Executable File
62 lines
1.4 KiB
Bash
Executable File
#!/bin/bash -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
|
|
|
|
DBNAME_BASE=${DBNAME}_base
|
|
|
|
$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
|
|
PGPASS_LINE="*:*:*:$USERNAME:$PASSWORD"
|
|
if ! $(grep -q "$PGPASS_LINE" ~/.pgpass); then
|
|
echo $PGPASS_LINE >> ~/.pgpass
|
|
fi
|
|
chmod go-rw ~/.pgpass
|
|
|
|
psql -h localhost postgres $USERNAME <<EOF
|
|
DROP DATABASE IF EXISTS $DBNAME;
|
|
DROP DATABASE IF EXISTS $DBNAME_BASE;
|
|
CREATE DATABASE $DBNAME_BASE
|
|
EOF
|
|
|
|
psql -h localhost $DBNAME_BASE $USERNAME <<EOF
|
|
CREATE SCHEMA zulip;
|
|
EOF
|
|
|
|
$ROOT_POSTGRES $DBNAME_BASE << EOF
|
|
CREATE EXTENSION tsearch_extras SCHEMA zulip;
|
|
EOF
|
|
|
|
psql -h localhost postgres $USERNAME <<EOF
|
|
CREATE DATABASE $DBNAME TEMPLATE $DBNAME_BASE;
|
|
EOF
|
|
|
|
echo "Database created"
|
|
|