<commit_before>#!/usr/bin/env bash
set -e

display_usage() {
    echo "Create dev and test databases. Dev database may optionally be seeded with data from a pg_dump file."
    echo
    echo "Usage:"
    echo "  bash docker/init.sh [-f dump_file]"
}

# Help
if [[ ( $1 == "--help") ||  ($1 == "-h")]]; then
    display_usage
    exit 0
fi

# Optional flag to use dump file
if [[ $# -gt 0 ]]; then
    getopts ":f:" opt || true;
    case $opt in
        f)
            if [ -f "$OPTARG" ]
            then
                FILE=$OPTARG
            else
                echo "Invalid path."
                exit 1
            fi
            ;;
        \?)
            # illegal option or argument
            display_usage
            exit 1
            ;;
        :)
            # -f present, but no path provided
            echo "Please specify the path."
            exit 1
            ;;
    esac
    if [[ $((OPTIND - $#)) -ne 1 ]]; then
        # too many args
        display_usage
        exit 1
    fi
fi

echo "Creating databases ..."
if [ "$FILE" ]; then
    echo "Loading data from $FILE ..."
    docker cp "$FILE" "$(docker-compose ps -q db)":/tmp/data.dump
    docker-compose exec db bash -c "pg_restore -l /tmp/data.dump | grep -v schema_migrations | grep -v ar_internal_metadata > /tmp/restore.list"
    docker-compose exec db pg_restore -L /tmp/restore.list --disable-triggers --username=postgres --verbose --no-owner -h localhost -d postgres /tmp/data.dump
    docker-compose exec db rm -f /tmp/data.dump /tmp/restore.list
fi<commit_msg>File now mandatory.<commit_after>#!/usr/bin/env bash
set -e

display_usage() {
    echo "Seed dev database with data from a pg_dump file."
    echo
    echo "Usage:"
    echo "  bash docker/init.sh -f dump_file"
}

# Help
if [[ ( $1 == "--help") ||  ($1 == "-h")]]; then
    display_usage
    exit 0
fi


getopts ":f:" opt || true;
case $opt in
    f)
        if [ -f "$OPTARG" ]
        then
            FILE=$OPTARG
        else
            echo "Invalid path."
            exit 1
        fi
        ;;
    \?)
        # illegal option or argument
        display_usage
        exit 1
        ;;
    :)
        # -f present, but no path provided
        echo "Please specify the path."
        exit 1
        ;;
esac
if [[ $((OPTIND - $#)) -ne 1 ]]; then
    # wrong number of args
    display_usage
    exit 1
fi

echo "Loading data from $FILE ..."
docker cp "$FILE" "$(docker-compose ps -q db)":/tmp/data.dump
docker-compose exec db bash -c "pg_restore -l /tmp/data.dump | grep -v schema_migrations | grep -v ar_internal_metadata > /tmp/restore.list"
docker-compose exec db pg_restore -L /tmp/restore.list --disable-triggers --username=postgres --verbose --no-owner -h localhost -d postgres /tmp/data.dump
docker-compose exec db rm -f /tmp/data.dump /tmp/restore.list

{'fraction_non_alphanumeric': 0.12677053824362605, 'fraction_numerical': 0.0060198300283286115, 'mean_word_length': 1.7777777777777777, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, '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': '1918171', 'n_tokens_mistral': 932, 'n_tokens_neox': 873, 'n_words': 300}