<commit_before>#!/bin/bash

set -u
set -o  errexit

cd `dirname $0`/../

echo "setting up test database"
./script/run_with_carton.sh ./script/mediawords_psql_wrapper.pl  --dump-env-commands --db-label test > /tmp/test_db_$$
source  /tmp/test_db_$$
echo "running pg_restore"
pg_restore --clean -d $PGDATABASE data/db_dumps/cc_blogs_mc_db.dump
echo "running mediawords_upgrade_db.pl --import"
MEDIAWORDS_FORCE_USING_TEST_DATABASE=1 ./script/run_with_carton.sh ./script/mediawords_upgrade_db.pl --import
echo "dumping"
pg_dump --format=custom $PGDATABASE >  data/db_dumps/cc_blogs_mc_db.dump
<commit_msg>Use dropdb and createdb to speed up upgrade_test_db.sh<commit_after>#!/bin/bash

set -u
set -o  errexit

cd `dirname $0`/../

echo "setting up test database"
./script/run_with_carton.sh ./script/mediawords_psql_wrapper.pl  --dump-env-commands --db-label test > /tmp/test_db_$$
source  /tmp/test_db_$$

if [[ "$PGDATABASE" != "mediacloud_test" ]]; then
    echo "aborting test database name ($PGDATABASE) must be mediacloud_test"
    exit -1
else
    echo "Dropping database $PGDATABASE"
    dropdb $PGDATABASE
    echo "Creating database $PGDATABASE"
    createdb $PGDATABASE
    echo "running pg_restore"
    pg_restore  -d $PGDATABASE data/db_dumps/cc_blogs_mc_db.dump
fi

echo "running mediawords_upgrade_db.pl --import"
MEDIAWORDS_FORCE_USING_TEST_DATABASE=1 ./script/run_with_carton.sh ./script/mediawords_upgrade_db.pl --import
echo "dumping"
pg_dump --format=custom $PGDATABASE >  data/db_dumps/cc_blogs_mc_db.dump

{'fraction_non_alphanumeric': 0.1175311884438608, 'fraction_numerical': 0.003282994090610637, 'mean_word_length': 4.404255319148936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6482057', 'n_tokens_mistral': 595, 'n_tokens_neox': 582, 'n_words': 123}