From f97bb6b65cce964048ba5fb943b4fa63a8c7467a Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 15 Jul 2019 17:04:33 -0700 Subject: [PATCH] postgres-create-db: Split into non-pgroonga and pgroonga scripts. Fixes #12655. Signed-off-by: Anders Kaseorg --- Dockerfile-postgresql | 3 ++- scripts/setup/create-db.sql | 6 ++++++ scripts/setup/create-pgroonga.sql | 3 +++ scripts/setup/postgres-create-db | 23 ----------------------- scripts/setup/postgres-init-db | 2 +- 5 files changed, 12 insertions(+), 25 deletions(-) create mode 100644 scripts/setup/create-db.sql create mode 100644 scripts/setup/create-pgroonga.sql delete mode 100755 scripts/setup/postgres-create-db diff --git a/Dockerfile-postgresql b/Dockerfile-postgresql index 3bb57e6384..c286ea22b0 100644 --- a/Dockerfile-postgresql +++ b/Dockerfile-postgresql @@ -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 \ diff --git a/scripts/setup/create-db.sql b/scripts/setup/create-db.sql new file mode 100644 index 0000000000..52135adaf8 --- /dev/null +++ b/scripts/setup/create-db.sql @@ -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; diff --git a/scripts/setup/create-pgroonga.sql b/scripts/setup/create-pgroonga.sql new file mode 100644 index 0000000000..063ff7c711 --- /dev/null +++ b/scripts/setup/create-pgroonga.sql @@ -0,0 +1,3 @@ +\connect zulip +CREATE EXTENSION pgroonga; +GRANT USAGE ON SCHEMA pgroonga TO zulip; diff --git a/scripts/setup/postgres-create-db b/scripts/setup/postgres-create-db deleted file mode 100755 index e4c5b0a269..0000000000 --- a/scripts/setup/postgres-create-db +++ /dev/null @@ -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 diff --git a/scripts/setup/postgres-init-db b/scripts/setup/postgres-init-db index 1a61f98047..932204df6e 100755 --- a/scripts/setup/postgres-init-db +++ b/scripts/setup/postgres-init-db @@ -48,7 +48,7 @@ su "$POSTGRES_USER" -c 'psql -v ON_ERROR_STOP=1 -e' <