Galleries duplicated after moving collection. No way to update path of original, tagged galleries

Something that seems like a bug, or at least a missing feature: after moving my collection to a new drive and rescanning, I ended up with duplicate copies of all my folder-based galleries, with different paths listed under “File Info”. My original galleries show the old drive as the path, no longer accessible.

I had manually added metadata (title, date, performers, tags, matching scenes, URLs) to some of my galleries, but the new versions with the current path are missing that metadata. If I delete the original versions of the galleries, I would lose all that work and have to re-add the metadata manually. But if I delete the new versions, they get recreated every time I rescan my collection. If I keep both copies, my gallery navigation is degraded and stats are inaccurate.

Ideally I could just manually change the original gallery’s folder path to the correct, current location, so no duplicate gallery would get created on rescanning. But it seems there is no way to do this. Rescanning from the gallery page doesn’t do anything.

Seems like someone else had a similar issue where duplicates were created after moving to a new PC: Deleting duplicate galleries. But I don’t think the “clean” operation will help me here. And shouldn’t the scan operation be able to detect if a gallery has been moved to a new path? I thought I remembered it working like that.

(I actually moved my collection twice, first running off a backup after a drive failure, and then to a new, long-term drive. But only the second migration created the duplicate galleries. I’m not sure why, but maybe it is because the new drive is using a different file system this time, exFAT vs NTFS. And maybe the other user’s new computer was on a different file system than their old one.)

Anyway, anyone know of a way to change the path associated with my original galleries, using a plugin or otherwise? If not, I might create a bug or feature request ticket on Github.

This sounds like a gap in the folder rename detection algorithm. There’s a few ways to fix this, but they all involve doing some data correction via SQL.

Specific instructions to fix this really depend on the current state of your database. If you’re comfortable with sharing your sqlite with me in a DM, I should be able to investigate and either fix and send back the sqlite file or give you specific instructions on how to fix.

To give a broad overview, there are two ways to potentially fix this:

On way is to delete the folder and containing file entries for the folder that has been duplicated, then rerun a scan to see if the rename folder detection works. This won’t be feasible if the folders have subfolders, or there are other video files in those folders.

Alternatively, if the image files were moved correctly but the gallery folder wasn’t (ie you can still access the image files in the old galleries), then you should be able to delete the newly created galleries, then use SQL to set the folder_id of the old gallery to the folder pointing to the new location. The specific SQL to do this will depend on what the old and new paths look like.

Thanks! Yes, this is the case:

the image files were moved correctly but the gallery folder wasn’t (ie you can still access the image files in the old galleries

The image files accessed from the old galleries have the correct, new path associated with them.

I think this would be a good learning opportunity for me to edit the DB using SQL myself.

I got the second suggested solution working using the sqlite3 editor for my local DB of my stash instance. But my workflow is pretty slow, like a minute per gallery, and I have like 200 left to go. Any suggestions for doing this faster/in bulk, with little risk of deleting galleries that weren’t duplicated or that I have already updated? Here’s what I’m doing:

  1. Open up my original galleries in Stash, filtering by path containing my old drive name (note, the drive name had spaces in it; maybe this is what caused the detection algorithm gap?)
  2. Using the gallery icon in grid view, navigate to the new, unlabeled gallery, and click on “File Info” to display the full path for the new folder I want to update to
  3. Find the folder ID of the new path using this SQL query, using text unique to that folder’s path:
    SELECT * FROM folders WHERE path LIKE ‘%text%’;
  4. Delete the new gallery in the Stash UI
  5. Navigate back to the original gallery in Stash and find the gallery ID by looking at the URL
  6. Use SQL to update the folder ID of the old gallery using the new folder ID and original Gallery ID:
    UPDATE galleries SET folder_id=#### WHERE id=####;

For the first suggested solution, I don’t want to delete the file entries in my folders because some of the images have individual tags or other metadata, and yes, a few of the folders might have subfolders or video files inside.

I posted this issue long back. i had a hard drive.(S). i have the same path as my C drive. the path length was long.
when i move files from C to S then rescan it automatically update the old path. then i bought 21 TB drive. and didn’t want to use same path so i created shorter path in my X drive. after that every time i move files from c to new drive then rescan it was creating new gallery instead of updating the path. this issue happened only for galleries. scenes worked fine. i always update gallery details , tags,studio performer in my local. i have created plugin and used for moving files from local to remove drive. it will move files and rescan the moved folders. i added additional step after rescanning. i created 2 views. old_drive gallery and new_drive gallery. i compared both and updated the new gallery with old gallery info. once the details are updated i ran clean on the local drive it cleared the old gallery.
it works for me. it is just clicking the button stash. i couldn’t share the plugin because i use many views in stash database which i can’t share.

I dealt with this somewhat recently. Here is the python script I used to fixup the database. I think what I did is disable gallery auto-creation from directories, run a scan to populate folder records in the database for the new paths, then ran the script. Back up your database first, YMMV, etc.

update-gallery-paths.py (912 Bytes)