snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
128
tools/setup/postgresql-init-dev-db
Executable file
128
tools/setup/postgresql-init-dev-db
Executable file
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
MODE=dev
|
||||
elif [[ $# == 1 ]]; then
|
||||
MODE=$1
|
||||
else
|
||||
echo "Too many arguments"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$MODE" == "dev" ]]; then
|
||||
USERNAME=zulip
|
||||
DBNAME=zulip
|
||||
STATUS_FILE_NAME=migration_status_dev
|
||||
elif [[ "$MODE" == "test" ]]; then
|
||||
USERNAME=zulip_test
|
||||
DBNAME=zulip_test
|
||||
STATUS_FILE_NAME=migration_status_test
|
||||
else
|
||||
echo "Usage instructions"
|
||||
echo "Run with either no arguments (sets up devel db for local deploy--zulip with user zulip)"
|
||||
echo "or specify 'test'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -x
|
||||
|
||||
POSTGRES_USER="postgres"
|
||||
if [ "$(uname)" = "OpenBSD" ]; then
|
||||
POSTGRES_USER="_postgresql"
|
||||
fi
|
||||
|
||||
ROOT_POSTGRES=(sudo -i -u "$POSTGRES_USER" psql)
|
||||
DEFAULT_DB=""
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
ROOT_POSTGRES=(psql)
|
||||
DEFAULT_DB="postgres"
|
||||
fi
|
||||
|
||||
if [ "$(uname)" = "OpenBSD" ]; then
|
||||
DEFAULT_DB="postgres"
|
||||
fi
|
||||
|
||||
VAGRANTUSERNAME=$(whoami)
|
||||
|
||||
PASSWORD=$("$(dirname "$0")/../../scripts/get-django-setting" LOCAL_DATABASE_PASSWORD)
|
||||
DBNAME_BASE=${DBNAME}_base
|
||||
|
||||
if ! pg_isready -U "$POSTGRES_USER" -q; then
|
||||
set +x
|
||||
echo
|
||||
echo 'ERROR: PostgreSQL server is not running! Ensure the service is enabled.'
|
||||
# shellcheck disable=SC2016
|
||||
echo 'ERROR: Try `sudo service postgresql start`?'
|
||||
echo "ERROR: You can easily test if you fixed it using: pg_isready -U \$POSTGRES_USER"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# We need to remove the stamp file indicating that the database
|
||||
# is properly provisioned with migrations.
|
||||
uuid_var_path=$("$(readlink -f "$(dirname "$0")/../../scripts/lib/zulip_tools.py")" get_dev_uuid)
|
||||
rm -f "$uuid_var_path/$STATUS_FILE_NAME"
|
||||
|
||||
"${ROOT_POSTGRES[@]}" -v ON_ERROR_STOP=1 -e "$DEFAULT_DB" <<EOF
|
||||
DO \$\$BEGIN
|
||||
CREATE USER $USERNAME;
|
||||
EXCEPTION WHEN duplicate_object THEN
|
||||
RAISE NOTICE '$USERNAME user already exists';
|
||||
END\$\$;
|
||||
ALTER USER $USERNAME PASSWORD '$PASSWORD';
|
||||
ALTER USER $USERNAME CREATEDB;
|
||||
EOF
|
||||
|
||||
if [ "$USERNAME" != "$VAGRANTUSERNAME" ]; then
|
||||
"${ROOT_POSTGRES[@]}" -v ON_ERROR_STOP=1 -e "$DEFAULT_DB" <<EOF
|
||||
DO \$\$BEGIN
|
||||
CREATE USER "$VAGRANTUSERNAME";
|
||||
EXCEPTION WHEN duplicate_object THEN
|
||||
RAISE NOTICE '$VAGRANTUSERNAME user already exists';
|
||||
END\$\$;
|
||||
GRANT $USERNAME TO "$VAGRANTUSERNAME";
|
||||
EOF
|
||||
fi
|
||||
|
||||
"${ROOT_POSTGRES[@]}" -v ON_ERROR_STOP=1 -e "$DEFAULT_DB" <<EOF
|
||||
ALTER ROLE "$VAGRANTUSERNAME" SET search_path TO zulip,public;
|
||||
EOF
|
||||
|
||||
umask go-rw
|
||||
PGPASS_PREFIX="*:*:*:$USERNAME:"
|
||||
PGPASS_ESCAPED_PREFIX="*:\\*:\\*:$USERNAME:"
|
||||
if ! grep -q "$PGPASS_ESCAPED_PREFIX" ~/.pgpass; then
|
||||
echo "$PGPASS_PREFIX$PASSWORD" >>~/.pgpass
|
||||
else
|
||||
sed -i "s/$PGPASS_ESCAPED_PREFIX.*\$/$PGPASS_PREFIX$PASSWORD/" ~/.pgpass
|
||||
fi
|
||||
chmod go-rw ~/.pgpass
|
||||
|
||||
PGHOST=localhost PGUSER="$USERNAME" \
|
||||
"$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" "$DBNAME" "$DBNAME_BASE"
|
||||
|
||||
psql -v ON_ERROR_STOP=1 -e -h localhost postgres "$USERNAME" <<EOF
|
||||
DROP DATABASE IF EXISTS $DBNAME;
|
||||
DROP DATABASE IF EXISTS $DBNAME_BASE;
|
||||
CREATE DATABASE $DBNAME_BASE
|
||||
EOF
|
||||
|
||||
"${ROOT_POSTGRES[@]}" -v ON_ERROR_STOP=1 -e "$DBNAME_BASE" <<EOF
|
||||
CREATE EXTENSION pgroonga;
|
||||
|
||||
-- Work around https://github.com/pgroonga/pgroonga/issues/335
|
||||
SELECT unnest(
|
||||
CASE WHEN current_setting('server_version_num')::integer >= 150000
|
||||
AND current_setting('pgroonga.enable_wal', TRUE) = 'on' IS NOT TRUE THEN
|
||||
ARRAY['ALTER SYSTEM SET pgroonga.enable_wal = ''on''', 'SELECT pg_reload_conf()']
|
||||
END
|
||||
) \gexec
|
||||
EOF
|
||||
|
||||
psql -v ON_ERROR_STOP=1 -e -h localhost postgres "$USERNAME" <<EOF
|
||||
CREATE DATABASE $DBNAME TEMPLATE $DBNAME_BASE;
|
||||
EOF
|
||||
|
||||
"$(dirname "$0")/../../scripts/setup/flush-memcached"
|
||||
|
||||
echo "Database created"
|
||||
Reference in New Issue
Block a user