SQL Question

I am asking about something I know is a bad idea, but I know the risks and have backups.

I had a drive get disconnected, and Plex removed/re-added the movies.

I am looking for a sql command to set the file last modified value as the date/time added to plex.

If you turn off the option to automatically empty the trash for the library, then a temporary disconnection won’t matter.

Yeah I know, I had it off, it got turned back on somehow, and I have since re-disabled it.

Do you have any recent backups you can restore from? That might be easier than the SQL route.

Outside of that, the following should set the “date added” to the file date for all items:

UPDATE metadata_items SET added_at=created_at;

If it’s just a specific library you want to update, you could specify the library_section_id:

UPDATE metadata_items SET added_at=created_at WHERE library_section_id=2;

Or based on the file path (% is a wildcard, so the following looks for all file paths that start with /mnt/driveA/):

UPDATE metadata_items SET added_at=created_at WHERE id IN (
    SELECT m.id FROM metadata_items m
        INNER JOIN media_items mi ON mi.metadata_item_id=m.id
        INNER JOIN media_parts p ON p.media_item_id=mi.id
    WHERE p.file LIKE "/mnt/driveA/%");

You’ll have to use Plex SQLite to modify metadata_items, since it uses custom extensions that aren’t part of the standard sqlite3 distribution.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.