diff --git a/invokeai/app/services/shared/sqlite/sqlite_util.py b/invokeai/app/services/shared/sqlite/sqlite_util.py index 7e27182f29..1eed0b4409 100644 --- a/invokeai/app/services/shared/sqlite/sqlite_util.py +++ b/invokeai/app/services/shared/sqlite/sqlite_util.py @@ -11,6 +11,7 @@ from invokeai.app.services.shared.sqlite_migrator.migrations.migration_5 import from invokeai.app.services.shared.sqlite_migrator.migrations.migration_6 import build_migration_6 from invokeai.app.services.shared.sqlite_migrator.migrations.migration_7 import build_migration_7 from invokeai.app.services.shared.sqlite_migrator.migrations.migration_8 import build_migration_8 +from invokeai.app.services.shared.sqlite_migrator.migrations.migration_9 import build_migration_9 from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_impl import SqliteMigrator @@ -39,6 +40,7 @@ def init_db(config: InvokeAIAppConfig, logger: Logger, image_files: ImageFileSto migrator.register_migration(build_migration_6()) migrator.register_migration(build_migration_7()) migrator.register_migration(build_migration_8(app_config=config)) + migrator.register_migration(build_migration_9()) migrator.run_migrations() return db diff --git a/invokeai/app/services/shared/sqlite_migrator/migrations/migration_9.py b/invokeai/app/services/shared/sqlite_migrator/migrations/migration_9.py new file mode 100644 index 0000000000..acc4ef5017 --- /dev/null +++ b/invokeai/app/services/shared/sqlite_migrator/migrations/migration_9.py @@ -0,0 +1,29 @@ +import sqlite3 + +from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_common import Migration + + +class Migration9Callback: + def __call__(self, cursor: sqlite3.Cursor) -> None: + self._empty_session_queue(cursor) + + def _empty_session_queue(self, cursor: sqlite3.Cursor) -> None: + """Empties the session queue. This is done to prevent any lingering session queue items from causing pydantic errors due to changed schemas.""" + + cursor.execute("DELETE FROM session_queue;") + + +def build_migration_9() -> Migration: + """ + Build the migration from database version 8 to 9. + + This migration does the following: + - Empties the session queue. This is done to prevent any lingering session queue items from causing pydantic errors due to changed schemas. + """ + migration_9 = Migration( + from_version=8, + to_version=9, + callback=Migration9Callback(), + ) + + return migration_9