postgres-create-db: Split into non-pgroonga and pgroonga scripts.

Fixes #12655.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-07-15 17:04:33 -07:00 committed by Tim Abbott
parent 1418b8b05f
commit f97bb6b65c
5 changed files with 12 additions and 25 deletions

View File

@ -27,7 +27,8 @@ ENV TSEARCH_EXTRAS_VERSION=0.4
ENV TSEARCH_EXTRAS_DEB=postgresql-${PG_MAJOR}-tsearch-extras_${TSEARCH_EXTRAS_VERSION}_amd64.deb
COPY --from=0 /${TSEARCH_EXTRAS_DEB} /tmp
COPY puppet/zulip/files/postgresql/zulip_english.stop /usr/share/postgresql/$PG_MAJOR/tsearch_data/zulip_english.stop
COPY scripts/setup/postgres-create-db /docker-entrypoint-initdb.d/postgres-create-db.sh
COPY scripts/setup/create-db.sql /docker-entrypoint-initdb.d/zulip-create-db.sql
COPY scripts/setup/create-pgroonga.sql /docker-entrypoint-initdb.d/zulip-create-pgroonga.sql
COPY scripts/setup/pgroonga-debian.asc /tmp
RUN apt-key add /tmp/pgroonga-debian.asc \
&& echo "deb http://packages.groonga.org/debian/ stretch main" > /etc/apt/sources.list.d/zulip.list \

View File

@ -0,0 +1,6 @@
CREATE USER zulip;
ALTER ROLE zulip SET search_path TO zulip,public;
CREATE DATABASE zulip OWNER=zulip;
\connect zulip
CREATE SCHEMA zulip AUTHORIZATION zulip;
CREATE EXTENSION tsearch_extras SCHEMA zulip;

View File

@ -0,0 +1,3 @@
\connect zulip
CREATE EXTENSION pgroonga;
GRANT USAGE ON SCHEMA pgroonga TO zulip;

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
set -e
set -x
# Make sure the current working directory is readable
cd /
DATABASE_CREATE="
CREATE USER zulip;
ALTER ROLE zulip SET search_path TO zulip,public;
CREATE DATABASE zulip OWNER=zulip;
\\connect zulip
CREATE SCHEMA zulip AUTHORIZATION zulip;
CREATE EXTENSION tsearch_extras SCHEMA zulip;
CREATE EXTENSION pgroonga;
GRANT USAGE ON SCHEMA pgroonga TO zulip;
"
if [ -f /.dockerenv ]; then
echo "$DATABASE_CREATE" | psql -v ON_ERROR_STOP=1 -e
else
echo "$DATABASE_CREATE" | su postgres -c 'psql -v ON_ERROR_STOP=1 -e'
fi

View File

@ -48,7 +48,7 @@ su "$POSTGRES_USER" -c 'psql -v ON_ERROR_STOP=1 -e' <<EOF
DROP DATABASE IF EXISTS zulip;
EOF
"$(dirname "$0")/postgres-create-db"
su "$POSTGRES_USER" -c 'psql -v ON_ERROR_STOP=1 -e' < "$(dirname "$0")/create-db.sql"
)
# Clear memcached to avoid contamination from previous database state