YES!!!
I finally managed to recover my iPhoto library!
But it was not easy. I had to hack into the database file to put up things right.
After a significant amount of trial-and-error, here is the procedure I came to, which finally worked for me (use at your own risk):
0. Make sure you make enough backups so as to revert to the previous state if something goes wrong!
1. Make a copy of your iPhoto Library [Show Package Contents]/Database/apdb/Library.apdb to your desktop.
This file contains most of the data involved for managing your iPhoto data.
2. Open this file using a SQLite database manager.
I used Navicat 9.1, which has nice import-export features. For direct editing, Base 2.0 is may be easier.
3. Open the table RKMaster.
This table contains all records for the individual pics of your library.
4. Correct the path of each of your pic files in the imagePath column to their current filepath.
This contains the path of your pic files at the time they were imported, and is not updated by iPhoto even though you have moved your pic files somewhere else.
If you have several thousands of paths to correct, a good idea is to export this column to a text file (also including the modelId column for referencing), and to correct paths using the substring Search&Replace function of your favorite text editor. Be sure to re-import the corrected data properly using the modelId column as references.
5. If needed, correct in the same manner the content of the fileVolumeUuid column to the value of the drive currently containing your picfiles.
If needed, obtain this value considering a pic which was recently imported from that drive.
6. If your drive name was modified, also correct its name in the name column of the RKVolume table.
Identify the proper record by considering its uuid previously obtained.
7. If you're happy with your work, quit the database managing program and put Library.apdb back in its original location inside your iPhoto Library.
Keep the older somewhere in case something goes wrong.
8. Run iPhoto to see if your work is successful!
At this point, you might consider rebuilding the Photo Library (hold alt-cmd while launching iPhoto) and choose Repair the iPhoto Library Database (Be sure to leave the Rebuild the iPhoto Library Database from automatic backup unchecked!). This might correct some possible unconsistencies resulting from your edits. Also, a good thing might be to rebuild all thumbnails. If iPhoto does not bug you for locating files during that process, you have possibly done your work right! If not, back to step 1.
As said, this worked for me, with no visible inconsistencies or side effects to be noticed in the behavior of iPhoto (at least for now). But possibly some knowledgable people might comment and improve that process, and some database script guru might also help automating this. Please comment.
Lessons learned (How I understand the things as far as I know):
A. Library.apdb stores the initial drive and path of the pic files at the time they were imported. This is not modified as the files are moved around.
B. Some other data (BLOBs?) is used to track the files at their actual location. Therefore, it seems OK to move the pic files after they were imported.
C. Unfortunately, this other data is broken if the file is recreated (even with same content and location), for example with a file-based backup and restore (Time Machine).
D. In that case, iPhoto is unable to recover the file if its current drive and path does not match the one when the file was imported, stored in the database. Also there is no mechanism in iPhoto to correct this data.
E. Therefore, it is very important to import pic files in iPhoto only when these are already in their final location! If not, your iPhoto Library won't survive a TimeMachine backup and restore! (Possibly, a block-based drive backup could work... I don't know).
F. ...And Apple should really, really fix this issue! (By correcting the stored filepath and drive to the current file location at least when the database is repaired, and by offering at least some basic file reconnection options).
Hope this helps...
- Pascal