Improved test database upgrade script