mirror of https://github.com/zulip/zulip.git
39 lines
989 B
Bash
Executable File
39 lines
989 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
set -x
|
|
|
|
# What user should we use for connecting to the database
|
|
POSTGRES_USER="${POSTGRES_USER:-postgres}"
|
|
|
|
# Shut down all services to ensure a quiescent state.
|
|
if [ -e "/var/run/supervisor.sock" ]; then
|
|
supervisorctl stop all
|
|
fi
|
|
|
|
# Drop any open connections to any old database. Hackishly call using
|
|
# source because postgres user can't read /root/zulip/scripts/setup.
|
|
source "$(dirname "$0")/terminate-psql-sessions" postgres zulip zulip_base
|
|
|
|
(
|
|
# Make sure the current working directory is readable by postgres
|
|
cd /
|
|
|
|
su "$POSTGRES_USER" -c psql <<EOF
|
|
CREATE USER zulip;
|
|
ALTER ROLE zulip SET search_path TO zulip,public;
|
|
DROP DATABASE IF EXISTS zulip;
|
|
CREATE DATABASE zulip OWNER=zulip;
|
|
EOF
|
|
|
|
su "$POSTGRES_USER" -c 'psql zulip' <<EOF
|
|
CREATE SCHEMA zulip AUTHORIZATION zulip;
|
|
CREATE EXTENSION tsearch_extras SCHEMA zulip;
|
|
EOF
|
|
)
|
|
|
|
# Clear memcached to avoid contamination from previous database state
|
|
sh "$(dirname "$0")/flush-memcached"
|
|
|
|
echo "Database created"
|
|
|