Make db upgrade script a bit more robust.