The migration can be done either before or after the upgrade. I’d do it before the upgrade, then the install and properly write the new location of the DB into the settings, so that future upgrades do not end up reverting back to the old location of the database.