Set dirty flag and update/store statistics after migration

see #1761 and #1735