diff --git a/invokeai/app/api/dependencies.py b/invokeai/app/api/dependencies.py index 2ab676d391..fb28eaac81 100644 --- a/invokeai/app/api/dependencies.py +++ b/invokeai/app/api/dependencies.py @@ -87,9 +87,9 @@ class ApiDependencies: migration_2.register_post_callback(partial(migrate_embedded_workflows, logger=logger, image_files=image_files)) migrator.register_migration(migration_1) migrator.register_migration(migration_2) - migrator.run_migrations() + did_migrate = migrator.run_migrations() - if not db.is_memory: + if not db.is_memory and did_migrate: db.reinitialize() configuration = config diff --git a/invokeai/app/services/shared/sqlite/sqlite_migrator.py b/invokeai/app/services/shared/sqlite/sqlite_migrator.py index b11f997648..7b6ea90874 100644 --- a/invokeai/app/services/shared/sqlite/sqlite_migrator.py +++ b/invokeai/app/services/shared/sqlite/sqlite_migrator.py @@ -168,7 +168,7 @@ class SQLiteMigrator: self._migrations.register(migration) self._logger.debug(f"Registered migration {migration.from_version} -> {migration.to_version}") - def run_migrations(self) -> None: + def run_migrations(self) -> bool: """Migrates the database to the latest version.""" with self._lock: # This throws if there is a problem. @@ -177,11 +177,11 @@ class SQLiteMigrator: if self._migrations.count == 0: self._logger.debug("No migrations registered") - return + return False if self._get_current_version(self._cursor) == self._migrations.latest_version: self._logger.debug("Database is up to date, no migrations to run") - return + return False self._logger.info("Database update needed") @@ -204,10 +204,9 @@ class SQLiteMigrator: else: # We are using a memory database. No special backup or special handling needed. self._run_migrations(self._cursor) - return self._logger.info("Database updated successfully") - return + return True def _run_migrations(self, temp_db_cursor: sqlite3.Cursor) -> None: next_migration = self._migrations.get(from_version=self._get_current_version(temp_db_cursor))