#! /bin/bash

rm -rf ./database_conversion
mkdir ./database_conversion
mkdir ./database_conversion/converted_database
#if [ -f `ls ./factory_defaults/*.sqlite | head -1` ]; then
if [ ! -d ./factory_defaults/database ]; then
	echo "Getting new database files from factory_defaults"
	cp ./factory_defaults/*.sqlite ./database_conversion/converted_database
else
	echo "Getting new database files from factory_defaults/database"
	cp  ./factory_defaults/database/*.sqlite ./database_conversion/converted_database
fi
mkdir ./database_conversion/new_columns
mkdir ./database_conversion/old_columns
./scripts/gen_columns.sh
./scripts/gen_inserts.sh
for f in `ls ./database_conversion/old_columns`; do
echo "Running Database Insert Script $f.sql"
sqlite3 ./database_conversion/converted_database/$f.sqlite < ./database_conversion/inserts/$f.sql
done

