[HowTo] Plex database modification - Moving media the right/wrong way

I had a similar need. I wanted to merge libraries. The actual location of the media was staying the same. I used sqlite browser. I looked at the table ‘library_locations’ to find Library B had an id of 21. I wanted to move a folder ‘/mnt/tv/animated’ to Library A which had an id 2.

What it was:

Library A (library_section_id = 2)
/mnt/tv/normal

Library B (library_section_id = 21)
/mnt/tv/animated

What I wanted:

Library A (library_section_id = 2)
/mnt/tv/normal
/mnt/tv/animated

Library B (library_section_id = 21)

Stopped plex. Backed up the db file. Updated the following tables. Started plex. All the metadata and watched state was still correct.

UPDATE section_locations
SET library_section_id = 2
WHERE
library_section_id = 21

UPDATE directories
SET library_section_id = 2
WHERE
library_section_id = 21

UPDATE media_items
SET library_section_id = 2
WHERE
library_section_id = 21


UPDATE metadata_item_views
SET library_section_id = 2
WHERE
library_section_id = 21

UPDATE metadata_items
SET library_section_id = 2
WHERE
library_section_id = 21
2 Likes