<commit_before>#!/bin/bash
cd "$(dirname "$0")" || exit

function createRole {
  echo "Setting up a database user."
  echo "You may be prompted for the password for the $USERNAME user."
  echo "As you type the password no output will be shown."
  echo
  sudo -u postgres psql -c "CREATE ROLE $USERNAME WITH LOGIN CREATEDB PASSWORD '<PASSWORD>'"
}

# If There is no Postgre role with the username, create it
[ $(psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$USERNAME'") != "1" ] && createRole

# Replaces "USERNAME" with the actual username in config.json
sed -i "s/USERNAME/$USERNAME/" config.json

echo "Postgre setup done"<commit_msg>Fix check of whether Postgres user exists<commit_after>#!/bin/bash
cd "$(dirname "$0")" || exit

function createRole {
  echo "Setting up a database user."
  echo "You may be prompted for the password for the $USERNAME user."
  echo "As you type the password no output will be shown."
  echo
  sudo -u postgres psql -c "CREATE ROLE $USERNAME WITH LOGIN CREATEDB PASSWORD '<PASSWORD>'"
}

# If There is no Postgre role with the username, create it
# psql will error if there is no role with the current user's name, e.g.:
# psql: FATAL:  role "user" does not exist
if psql postgres -c "" &> /dev/null
then
  echo "PostgreSQL user $USERNAME already exists so it will not be created."
else
  createRole
fi

# Replaces "USERNAME" with the actual username in config.json
sed -i "s/USERNAME/$USERNAME/" config.json

echo "Postgre setup done"
{'fraction_non_alphanumeric': 0.09973045822102426, 'fraction_numerical': 0.0026954177897574125, 'mean_word_length': 4.016891891891892, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '3912591', 'n_tokens_mistral': 478, 'n_tokens_neox': 460, 'n_words': 212}