diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index 77fdc23c14..18f59cbc16 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -140,11 +140,6 @@ def make_deploy_path(): timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) return os.path.join(DEPLOYMENTS_DIR, timestamp) -if __name__ == '__main__': - cmd = sys.argv[1] - if cmd == 'make_deploy_path': - print(make_deploy_path()) - TEMPLATE_DATABASE_DIR = "test-backend/databases" def get_dev_uuid_var_path(create_if_missing=False): # type: (bool) -> str @@ -477,3 +472,10 @@ def get_or_create_dev_uuid_var_path(path: str) -> str: absolute_path = '{}/{}'.format(get_dev_uuid_var_path(), path) os.makedirs(absolute_path, exist_ok=True) return absolute_path + +if __name__ == '__main__': + cmd = sys.argv[1] + if cmd == 'make_deploy_path': + print(make_deploy_path()) + elif cmd == 'get_dev_uuid': + print(get_dev_uuid_var_path()) diff --git a/tools/setup/postgres-init-dev-db b/tools/setup/postgres-init-dev-db index cfa9bf8ecd..cfc69685d1 100755 --- a/tools/setup/postgres-init-dev-db +++ b/tools/setup/postgres-init-dev-db @@ -25,15 +25,17 @@ if [[ $# == 0 ]]; then PASSWORD=$("$(dirname "$0")/../../scripts/get-django-setting" LOCAL_DATABASE_PASSWORD) DBNAME=zulip SEARCH_PATH="$USERNAME",public -elif [[ $# == 4 ]]; then + STATUS_FILE_NAME="migration_status_dev" +elif [[ $# == 5 ]]; then USERNAME=$1 PASSWORD=$2 DBNAME=$3 SEARCH_PATH=$4 + STATUS_FILE_NAME=$5 else echo "Usage Instructions" echo "Run with either no arguments (sets up devel db for local deploy--zulip with user zulip)" - echo "or specify " + echo "or specify " exit fi @@ -49,6 +51,11 @@ if ! pg_isready -U "$POSTGRES_USER" -q; then 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; diff --git a/tools/setup/postgres-init-test-db b/tools/setup/postgres-init-test-db index 57516fe14d..185f30ee23 100755 --- a/tools/setup/postgres-init-test-db +++ b/tools/setup/postgres-init-test-db @@ -2,4 +2,4 @@ set -x set -e -"$(dirname "$0")/postgres-init-dev-db" zulip_test "$("$(dirname "$0")/../../scripts/get-django-setting" LOCAL_DATABASE_PASSWORD)" zulip_test zulip,public +"$(dirname "$0")/postgres-init-dev-db" zulip_test "$("$(dirname "$0")/../../scripts/get-django-setting" LOCAL_DATABASE_PASSWORD)" zulip_test zulip,public migration_status_test