#!/bin/bash

# This script is intendent to be used to extend bkserver database to 
# to be able to hold both bkserver and lbproxy jobs.
# The operation should be non-destructive, i.e. all data should persist
# and continue to be fully usable.
 
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

}

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 -u lbserver $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;"

