The schema upgrade is very simple and safe but make sure the current database schema is in version 4.0.
First things first - make a database backup:
tar -czf derbyDB.tar.gz /path/to/derbyDB
If you need to restore database for any reason simply extract files from the backup archive:
rm -rf /path/to/derbyDB tar -xf derbyDB.tar.gz
Now we can run schema upgrade script
java -Dij.protocol=jdbc:derby: -Dij.database="/path/to/derbyDB" \ -Dderby.system.home=`pwd` \ -cp libs/derby.jar:libs/derbytools.jar:jars/tigase-server.jar \ org.apache.derby.tools.ij database/postgresql-schema-upgrade-to-5-1.sql