refactor database upgrade sql script