AppleScript to make the preview image become the master in Aperture library?
In the case that your library has SOME structure left to it, press and hold the command and option keys, then open Aperture. A window will appear that says, "Photo Library First Aid". Tick the "Rebuild Database" option. I would recommend duplicating the library in case something goes terribly wrong.