<commit_before>#!/usr/bin/env bash

# no-output on pushd and popd
pushd () {
    command pushd "$@" > /dev/null
}

popd () {
    command popd "$@" > /dev/null
}

set_env() {
    export MCDB_PORT=30815
    export RETHINKDB_HTTP_PORT=8090
    export RETHINKDB_CLUSTER_PORT=31815
}

print_message() {
    cat <<- EOF
This script will start the Materials Commons test environment with
a useful, empty, test database. No projects, Experiments or other
data is defined. See the content of the script for details.
There are 4 users defined: <EMAIL>, <EMAIL>, <EMAIL>,
and <EMAIL>. For each user the password is set to '<PASSWORD>' and
specific apikeys are set for the users 'test' and 'another'. The user
'admin' is defined as an admin, and the user 'tadmin' is defined as a
template admin. See makeUserForTest.py for details on users.
EOF
}

set_locations() {
    # location of this script, scripts, backend
    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    pushd $DIR
    BASE=`pwd`
    pushd '..'
    SCRIPTS=`pwd`
    pushd '..'
    BACKEND=`pwd`
    popd
    popd
    popd
}

print_env_and_locations() {
    echo "----------- Test DB rebuild ENV settings --------------"
    echo "  BASE - the location of this script and other helper scripts"
    echo "  BASE      ${BASE} "
    echo "  SCRIPTS - the location of the materialscommons.org/backend/scripts folder"
    echo "  SCRIPTS   ${SCRIPTS} "
    echo "  BACKEND - the location of the materialscommons.org/backend folder"
    echo "  BACKEND   ${BACKEND} "
    echo "  MCDB_PORT               ${MCDB_PORT} "
    echo "  RETHINKDB_HTTP_PORT     ${RETHINKDB_HTTP_PORT} "
    echo "  RETHINKDB_CLUSTER_PORT  ${RETHINKDB_CLUSTER_PORT} "
    echo "======================================================="
}


start_empty_rethinkdb() {
    echo "Starting rethinkdb with no data..."
    (cd ${MCDB_DIR}; rethinkdb --driver-port ${MCDB_PORT} --cluster-port ${RETHINKDB_CLUSTER_PORT} --http-port ${RETHINKDB_HTTP_PORT} --daemon)
    scripts/db_running.py --port ${MCDB_PORT}
    echo "Started."
}

safely_start_rethinkdb() {
    pushd $BACKEND
    ./mcservers sstop rethinkdb
    sleep 2
    start_empty_rethinkdb
    popd
}

rebuild_test_database() {
    pushd $BASE
    echo "Building minimal test DB in rethinkdb..."
    MC_USERPW=test build-test-db.sh > /dev/null
    echo "Built."
    popd
}

set_env
print_message
set_locations
print_env_and_locations
safely_start_rethinkdb
rebuild_test_database

echo "Done create test DB."<commit_msg>Minor updates to script for building test database<commit_after>#!/usr/bin/env bash

# no-output on pushd and popd
pushd () {
    command pushd "$@" > /dev/null
}

popd () {
    command popd "$@" > /dev/null
}

set_env() {
    export MCDB_PORT=30815
    export RETHINKDB_HTTP_PORT=8090
    export RETHINKDB_CLUSTER_PORT=31815
}

print_message() {
    cat <<- EOF
This script will start RethinkDB for Materials Commons with
a useful, empty, test database. No projects, Experiments or other
data is defined. See the content of the script for details.
There are 4 users defined: <EMAIL>, <EMAIL>, <EMAIL>,
and <EMAIL>. For each user the password is set to '<PASSWORD>' and
specific apikeys are set for the users 'test' and 'another'. The user
'admin' is defined as an admin, and the user 'tadmin' is defined as a
template admin. See makeUserForTest.py for details on users.
EOF
}

set_locations() {
    # location of this script, scripts, backend
    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    pushd $DIR
    BASE=`pwd`
    pushd '..'
    SCRIPTS=`pwd`
    pushd '..'
    BACKEND=`pwd`
    popd
    popd
    popd
}

print_env_and_locations() {
    echo "----------- Test DB rebuild ENV settings --------------"
    echo "  BASE - the location of this script and other helper scripts"
    echo "  BASE      ${BASE} "
    echo "  SCRIPTS - the location of the materialscommons.org/backend/scripts folder"
    echo "  SCRIPTS   ${SCRIPTS} "
    echo "  BACKEND - the location of the materialscommons.org/backend folder"
    echo "  BACKEND   ${BACKEND} "
    echo "  MCDB_PORT               ${MCDB_PORT} "
    echo "  RETHINKDB_HTTP_PORT     ${RETHINKDB_HTTP_PORT} "
    echo "  RETHINKDB_CLUSTER_PORT  ${RETHINKDB_CLUSTER_PORT} "
    echo "======================================================="
}


start_empty_rethinkdb() {
    echo "Starting rethinkdb with only tables and indexes ..."
    (cd ${MCDB_DIR}; rethinkdb --driver-port ${MCDB_PORT} --cluster-port ${RETHINKDB_CLUSTER_PORT} --http-port ${RETHINKDB_HTTP_PORT} --daemon)
    scripts/db_running.py --port ${MCDB_PORT}
    echo "Started."
}

safely_start_rethinkdb() {
    pushd $BACKEND
    ./mcservers sstop rethinkdb
    sleep 2
    start_empty_rethinkdb
    popd
}

rebuild_test_database() {
    pushd $BASE
    echo "Building minimal test DB in rethinkdb..."
    MC_USERPW=test build-test-db.sh > /dev/null
    echo "Built test DB."
    popd
}

set_env
print_message
set_locations
print_env_and_locations
safely_start_rethinkdb
rebuild_test_database

echo "Done create test DB."
{'fraction_non_alphanumeric': 0.13209412695273878, 'fraction_numerical': 0.006723353767055566, 'mean_word_length': 3.1663920922570017, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4219538', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1698, 'n_words': 499}