RESTORE=${DIRNAME}/${DATE}-pl5.sql
FAKE=${DIRNAME}/input-pl4.sql
VIEWS_SQL=$DIRNAME/${DATE}-views5.sql
RESTORE=${DIRNAME}/${DATE}-pl5.sql
FAKE=${DIRNAME}/input-pl4.sql
VIEWS_SQL=$DIRNAME/${DATE}-views5.sql
# so this script will drop the planetlab5 DB and re-create it from scratch
# with the contents of the planetlab4 DB that is epxected to exist
function warning () {
# so this script will drop the planetlab5 DB and re-create it from scratch
# with the contents of the planetlab4 DB that is epxected to exist
function warning () {
echo "$COMMAND"
echo "This script is designed to ease the migration from myplc 4.2 to 5.0"
echo "You can run it before of after you install a 5.0 myplc"
echo "$COMMAND"
echo "This script is designed to ease the migration from myplc 4.2 to 5.0"
echo "You can run it before of after you install a 5.0 myplc"
echo "It will attempt to re-create the planetlab5 database from planetlab4"
echo "The planetlab5 database is renamed, not dropped, if it is found on the system"
echo "It will attempt to re-create the planetlab5 database from planetlab4"
echo "The planetlab5 database is renamed, not dropped, if it is found on the system"
[ -f $MIGRATION_SED ] || { echo $MIGRATION_SED not found - exiting ; exit 1; }
[ -f $MIGRATION_SQL ] || { echo $MIGRATION_SQL not found - exiting ; exit 1; }
[ -f $SCHEMA_SQL ] || { echo $SCHEMA_SQL not found - exiting ; exit 1; }
[ -f $MIGRATION_SED ] || { echo $MIGRATION_SED not found - exiting ; exit 1; }
[ -f $MIGRATION_SQL ] || { echo $MIGRATION_SQL not found - exiting ; exit 1; }
[ -f $SCHEMA_SQL ] || { echo $SCHEMA_SQL not found - exiting ; exit 1; }
run "Creating planetlab5 database" createdb --user=postgres --encoding=UNICODE --owner=$PLC_DB_USER planetlab5
run "Loading language plpgsql" createlang -U postgres plpgsql planetlab5 || true
run "Populating planetlab5 from $RESTORE" psql --user=postgres -f $RESTORE planetlab5
run "Creating planetlab5 database" createdb --user=postgres --encoding=UNICODE --owner=$PLC_DB_USER planetlab5
run "Loading language plpgsql" createlang -U postgres plpgsql planetlab5 || true
run "Populating planetlab5 from $RESTORE" psql --user=postgres -f $RESTORE planetlab5
run "Fine-tuning it with $MIGRATION_SQL" psql --user=$PLC_DB_USER -f $MIGRATION_SQL planetlab5
run "Extracting views definitions from $SCHEMA_SQL" ./extract-views.py $SCHEMA_SQL $VIEWS_SQL
run "Inserting views definitions in planetlab5" \
run "Fine-tuning it with $MIGRATION_SQL" psql --user=$PLC_DB_USER -f $MIGRATION_SQL planetlab5
run "Extracting views definitions from $SCHEMA_SQL" ./extract-views.py $SCHEMA_SQL $VIEWS_SQL
run "Inserting views definitions in planetlab5" \