Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 69 lines (51 sloc) 1.65 KB
#!/bin/bash
if [ -z "$1" ];
then echo "please provide the path to the sql file that contains the old
database";
exit 1;
fi
if [ ! -f $1 ];
then echo "sql file not found!";
exit 1;
fi
SQL_FILE=$1;
echo "using sql file: $SQL_FILE";
if [ -z "config.json" ];
then echo "config.json file is missing and need to read database credentials";
exit 1;
fi
echo "found config.json"
DB_USER=`python -c 'import json; c=json.load(open("config.json")); print c["db_user"]'`
DB_PASS=`python -c 'import json; c=json.load(open("config.json")); print c["db_user"]'`
DB_NAME=`python -c 'import json; c=json.load(open("config.json")); print c["db_name"]'`
MYSQL="mysql --user=$DB_USER --password=$DB_PASS -D $DB_NAME"
echo "using mysql username $DB_USER"
echo "using mysql database $DB_NAME"
$MYSQL < $SQL_FILE
rc=$?;
if [ $rc -ne 0 ]; then
echo "ERROR: unable to import the provided sql file.";
exit 1;
fi
echo "successfully imported provided sql file";
$MYSQL < resources/scripts/sql/drop.sql;
rc=$?;
if [ $rc -ne 0 ]; then
echo "ERROR: failed to drop previous version of new schema in database $DB_NAME.";
exit 1;
fi
echo "successfully removed previous version of the new schema in database $DB_NAME.";
$MYSQL < resources/scripts/sql/schema.sql;
rc=$?;
if [ $rc -ne 0 ]; then
echo "ERROR: failed to create new schema tables in database $DB_NAME.";
exit 1;
fi
echo "successfully created new table schemas in database $DB_NAME.";
$MYSQL < resources/scripts/sql/migration.sql;
rc=$?;
if [ $rc -ne 0 ]; then
echo "ERROR: failed to migrate to new schema in database $DB_NAME.";
exit 1;
fi
echo "successfully migrated tables to new schema in database $DB_NAME.";