<commit_before>#!/bin/bash

set -u
set -o  errexit

# Include PostgreSQL path helpers
PWD="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$PWD/postgresql_helpers.inc.sh"

# 
QUERY_CONFIG="$PWD/../script/run_with_carton.sh $PWD/../script/mediawords_query_config.pl"


echo "WARNING: This script will delete the following Media Cloud databases and users:"
for db_selector in "${DB_CREDENTIALS_SELECTORS[@]}"; do
    db_credentials_label=`$QUERY_CONFIG "$db_selector/label"`
    echo "    * Label: $db_credentials_label"
    db_credentials_host=`$QUERY_CONFIG "$db_selector/host"`
    echo "      Host: $db_credentials_host"
    db_credentials_user=`$QUERY_CONFIG "$db_selector/user"`
    echo "      Username: $db_credentials_user"
    db_credentials_db=`$QUERY_CONFIG "$db_selector/db"`
    echo "      Database: $db_credentials_db"
    echo
done
echo "Are you sure you want to do this (y/n)?"
read REPLY

if [ $REPLY != "y" ]; then
    echo "Exiting..."
    exit 1
fi

for db_selector in "${DB_CREDENTIALS_SELECTORS[@]}"; do

    db_credentials_label=`$QUERY_CONFIG "$db_selector/label"`
    echo "Dropping database with label '$db_credentials_label'..."

    db_credentials_host=`$QUERY_CONFIG "$db_selector/host"`
    db_credentials_user=`$QUERY_CONFIG "$db_selector/user"`
    db_credentials_db=`$QUERY_CONFIG "$db_selector/db"`

    #
    # Drop database
    #
    echo "    Dropping database '$db_credentials_db' on host '$db_credentials_host'..."
    dropdb_exec=`run_dropdb "$db_credentials_host" "$db_credentials_db"`

    if [[ "$dropdb_exec" == *"ERROR"* ]]; then
        if [[ "$dropdb_exec" == *"does not exist"* ]]; then
            echo "        Database '$db_credentials_db' does not exist, skipping."
        elif [[ -n "$dropdb_exec" ]]; then
            echo "        PostgreSQL error while dropping database '$db_credentials_db': $dropdb_exec"
            exit 1
        fi
    fi
    echo "    Done dropping database '$db_credentials_db'."

    #
    # Drop user if there are no more databases owned by it<commit_msg>Add quotes around "$REPLY" so that the script doesn't take an empty input string as a "yes"<commit_after>#!/bin/bash

set -u
set -o  errexit

# Include PostgreSQL path helpers
PWD="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$PWD/postgresql_helpers.inc.sh"

# 
QUERY_CONFIG="$PWD/../script/run_with_carton.sh $PWD/../script/mediawords_query_config.pl"


echo "WARNING: This script will delete the following Media Cloud databases and users:"
for db_selector in "${DB_CREDENTIALS_SELECTORS[@]}"; do
    db_credentials_label=`$QUERY_CONFIG "$db_selector/label"`
    echo "    * Label: $db_credentials_label"
    db_credentials_host=`$QUERY_CONFIG "$db_selector/host"`
    echo "      Host: $db_credentials_host"
    db_credentials_user=`$QUERY_CONFIG "$db_selector/user"`
    echo "      Username: $db_credentials_user"
    db_credentials_db=`$QUERY_CONFIG "$db_selector/db"`
    echo "      Database: $db_credentials_db"
    echo
done
echo "Are you sure you want to do this (y/n)?"
read REPLY

if [ "$REPLY" != "y" ]; then
    echo "Exiting..."
    exit 1
fi

for db_selector in "${DB_CREDENTIALS_SELECTORS[@]}"; do

    db_credentials_label=`$QUERY_CONFIG "$db_selector/label"`
    echo "Dropping database with label '$db_credentials_label'..."

    db_credentials_host=`$QUERY_CONFIG "$db_selector/host"`
    db_credentials_user=`$QUERY_CONFIG "$db_selector/user"`
    db_credentials_db=`$QUERY_CONFIG "$db_selector/db"`

    #
    # Drop database
    #
    echo "    Dropping database '$db_credentials_db' on host '$db_credentials_host'..."
    dropdb_exec=`run_dropdb "$db_credentials_host" "$db_credentials_db"`

    if [[ "$dropdb_exec" == *"ERROR"* ]]; then
        if [[ "$dropdb_exec" == *"does not exist"* ]]; then
            echo "        Database '$db_credentials_db' does not exist, skipping."
        elif [[ -n "$dropdb_exec" ]]; then
            echo "        PostgreSQL error while dropping database '$db_credentials_db': $dropdb_exec"
            exit 1
        fi
    fi
    echo "    Done dropping database '$db_credentials_db'."

    #
    # Drop user if there are no more databases owned by it
{'fraction_non_alphanumeric': 0.12931034482758622, 'fraction_numerical': 0.0014367816091954023, 'mean_word_length': 3.6052921719955897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4617580', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1392, 'n_words': 333}