Almost fully functional migration script