Pete Wenzel | 10 Jan 2005 08:48
Picon
Favicon

SQL Script to Fix Missing Relations

I often find that when modifying the metadata in my library, entire
albums, genres or artists will suddenly disappear.  Upon examination of
the tracks table, I find that they still exist there, but NetJuke has
inexplicably deleted the relevant row from the albums, genres or artists
table, even though they are still in use.  This renders all tracks that
reference that particular ID "lost" (meaning they no longer show up in
any search or browse operations).

So, I wrote the attached SQL script that identifies and recreates these
missing keys, making the lost tracks reappear.  However, since the true
name of the artist, genre or album has been lost, the new entry is of
the form "LOST_ALBUM_NAME"; but then it is a simple matter to use the
web interface to correct these instances.

Use at your own risk, but I know it's saved my database numerous times
by correcting this type of inconsistency.  Perhaps something like this
can be included among the database maintenance functions.  Or better yet,
someone might correct the bug that causes this problem in the first place.

--Pete
use netjuke;

#mysql> describe netjuke_albums;
#+-----------+--------------+------+-----+---------+----------------+
#| Field     | Type         | Null | Key | Default | Extra          |
#+-----------+--------------+------+-----+---------+----------------+
#| id        | int(11)      |      | PRI | NULL    | auto_increment |
#| name      | varchar(100) |      | MUL | N/A     |                |
(Continue reading)


Gmane