Skip to content

Feature(backend): Add a command-line utility for running gallery maintenance#8827

Open
lstein wants to merge 2 commits intoinvoke-ai:mainfrom
lstein:lstein/bugfix/gallery-maintenance-script
Open

Feature(backend): Add a command-line utility for running gallery maintenance#8827
lstein wants to merge 2 commits intoinvoke-ai:mainfrom
lstein:lstein/bugfix/gallery-maintenance-script

Conversation

@lstein
Copy link
Collaborator

@lstein lstein commented Feb 1, 2026

Summary

This PR provides a command-line utility for synchronizing the InvokeAI database with the image galleries. It cures problems arising from image files that were removed by the OS from the outputs directory, missing thumbnails, and extraneous image files that have no corresponding database entries.

It has three functions:

  1. Clear entries in the database where the matching image file is missing from the outputs directory.
  2. Identify image files that are in the outputs directory but missing from the database (they are archived).
  3. Regenerating missing thumbnails.

This functionality actually dates back to a 3.x era invokeai.backend.util.db_maintenance.py module, that hasn't worked in a while. I made minor fixes to it and added an executable wrapper in scripts.

Related Issues / Discussions

Closes #4365

QA Instructions

Because this script will mess with your galleries, you might wish to create a fresh root directory to experiment with.

  1. Introduce issues into your gallery by:
    a. Removing images from outputs/images
    b. Adding image files that were generated outside of InvokeAI.
    c. Removing thumbnails from outputs/images/thumbnails
  2. Run python3 ./scripts/gallery_maintenance.py --root INVOKEAI_ROOT --operation all

You should see the following actions:

  • The removed images are deleted from the database.
  • The additional image files are moved into the archive directory
  • The missing thumbnails are regenerated.

Merge Plan

Simple merge.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@lstein lstein self-assigned this Feb 1, 2026
@github-actions github-actions bot added python PRs that change python files backend PRs that change backend files labels Feb 1, 2026
@lstein lstein assigned dunkeroni and unassigned lstein Feb 1, 2026
@lstein lstein added the v6.12.0 Intended for 6.12.0 release label Feb 1, 2026
@lstein
Copy link
Collaborator Author

lstein commented Feb 4, 2026

Note that @Pfannkuchensack has a more comprehensive db maintenance/gallery package in a separate repository at https://github.com/Pfannkuchensack/sqlite_invokeai_db_tool . We should promote it in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend PRs that change backend files python PRs that change python files v6.12.0 Intended for 6.12.0 release

Projects

Status: 6.12.x

Development

Successfully merging this pull request may close these issues.

[enhancement]: "Remove orphans" from Gallery database

2 participants