#!/bin/bash

usage() {
cat <<EOF
NAME:
	glite-lb-migrate_db2version40
		script for migrating older LB server database
		to new schema required for storing job connections 
USAGE:
	glite-lb-migrate_db2version40 [-d db_name]

		-d db_name	non-default database name
EOF

}

MYSQL_ARGS=${MYSQL_ARGS:-'-u lbserver'}
MYSQL_PASSWORD=${MYSQL_PASSWORD:-''}

while getopts "d:h" OPTION 
do
    case "$OPTION" in
    "d") DB_NAME=$OPTARG
    ;;

    "h") 
	usage;
	exit;
    ;;

    esac
done

if [ -z "$DB_NAME" ]; then
	DB_NAME="lbserver20"
fi


# job connections table
mysql $MYSQL_ARGS --password="$MYSQL_PASSWORD" $DB_NAME -e "\
create table job_connections (\
        jobid_from      char(32)        binary not null,\
        jobid_to        char(32)        binary not null,\
        jobtype         int             not null,\
        connection      int             not null,\
        primary key (jobid_from, jobid_to)\
) engine=innodb;"

