BS-8439, add indexes and check database consistency before migration