#!/bin/bash -e

# FIXE: hacked and not general

# Ensure this dir and bin directory are in the path
dir=../genbank-update/test #`dirname $0`
PATH="$dir:$dir/../bin:$dir/../bin/${MACHTYPE}:${PATH}"

# FIXME: need ot parameterize or figure out version; check for unreadable dirs.

db=hg13test
version=132.0

shopt -s nullglob

rm -f core.*  data/ignore.idx
rm -rf out
mkdir -p out
reset-db 
chmod ug+rwx data/processed/*/* data/aligned/*/$db/*
db-load-test -initialLoad all

dailies=`(cd data/processed/genbank.${version} && echo daily.*)`

reset-db 
chmod a-rwx data/processed/genbank.${version}/daily.* data/aligned/genbank.${version}/$db/daily.*
db-load-test full

for daily in $dailies ; do
    chmod ug+rwx data/processed/genbank.${version}/$daily
    al=data/aligned/genbank.${version}/$db/$daily
    if [ -e $al ] ; then
        chmod ug+rwx $al
    fi
    if [ $daily = "daily.1220" ] ; then
        cp ignore.idx data
        #exit 1
    fi
    db-load-test $daily
done

chmod ug+rwx data/processed/*/* aligned/*/$db/*

# list of tables and selected tab contents between the all load and the
# incremental load. The extFile table is expected to differ, since we don't
# clean it up.  Diff it for inspection, but don't report errors.
diff -r out/all/tbls out/$daily/tbls >out/all-last.diffs

diff out/all/extFile.tbl out/$daily/extFile.tbl >out/extFile.diffs || true

