#!/bin/sh

TABLE=user_experiment_role

CURRENT_DIR=`pwd`
MY_DIR=`dirname $0` && cd $MY_DIR && MY_DIR=`pwd`
cd $CURRENT_DIR

POPULATE_SCRIPT=populate_$TABLE.sql

cp $POPULATE_SCRIPT $POPULATE_SCRIPT.new

# eliminate old manager role
cat $POPULATE_SCRIPT.new | grep -v "2)" > $POPULATE_SCRIPT.new.2 && mv $POPULATE_SCRIPT.new.2 $POPULATE_SCRIPT.new || exit 1

# fix old PI role
cat $POPULATE_SCRIPT.new | sed 's?3)?1)?g' > $POPULATE_SCRIPT.new.2 && mv $POPULATE_SCRIPT.new.2 $POPULATE_SCRIPT.new || exit 1

# fix old user role
cat $POPULATE_SCRIPT.new | sed 's?4)?2)?g' > $POPULATE_SCRIPT.new.2 && mv $POPULATE_SCRIPT.new.2 $POPULATE_SCRIPT.new || exit 1
