mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(db): add migration 5 to drop graph_executions
table
This commit is contained in:
parent
30367deeca
commit
198e8c9d55
@ -7,6 +7,7 @@ from invokeai.app.services.shared.sqlite_migrator.migrations.migration_1 import
|
|||||||
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_2 import build_migration_2
|
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_2 import build_migration_2
|
||||||
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_3 import build_migration_3
|
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_3 import build_migration_3
|
||||||
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_4 import build_migration_4
|
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_4 import build_migration_4
|
||||||
|
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_5 import build_migration_5
|
||||||
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_impl import SqliteMigrator
|
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_impl import SqliteMigrator
|
||||||
|
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ def init_db(config: InvokeAIAppConfig, logger: Logger, image_files: ImageFileSto
|
|||||||
migrator.register_migration(build_migration_2(image_files=image_files, logger=logger))
|
migrator.register_migration(build_migration_2(image_files=image_files, logger=logger))
|
||||||
migrator.register_migration(build_migration_3(app_config=config, logger=logger))
|
migrator.register_migration(build_migration_3(app_config=config, logger=logger))
|
||||||
migrator.register_migration(build_migration_4())
|
migrator.register_migration(build_migration_4())
|
||||||
|
migrator.register_migration(build_migration_5(logger=logger))
|
||||||
migrator.run_migrations()
|
migrator.run_migrations()
|
||||||
|
|
||||||
return db
|
return db
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
import sqlite3
|
||||||
|
from logging import Logger
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
|
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_common import Migration
|
||||||
|
|
||||||
|
|
||||||
|
class Migration5Callback:
|
||||||
|
def __init__(self, logger: Logger):
|
||||||
|
self._logger = logger
|
||||||
|
|
||||||
|
def __call__(self, cursor: sqlite3.Cursor) -> None:
|
||||||
|
self._drop_graph_executions(cursor)
|
||||||
|
|
||||||
|
def _drop_graph_executions(self, cursor: sqlite3.Cursor) -> None:
|
||||||
|
"""Drops the `graph_executions` table."""
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""--sql
|
||||||
|
SELECT COUNT(*) FROM graph_executions;
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
count = cast(int, cursor.fetchone()[0])
|
||||||
|
self._logger.info(f"Clearing {count} old sessions from database")
|
||||||
|
cursor.execute(
|
||||||
|
"""--sql
|
||||||
|
DROP TABLE IF EXISTS graph_executions;
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def build_migration_5(logger: Logger) -> Migration:
|
||||||
|
"""
|
||||||
|
Build the migration from database version 4 to 5.
|
||||||
|
|
||||||
|
Introduced in v3.6.3, this migration:
|
||||||
|
- Drops the `graph_executions` table. We are able to do this because we are moving the graph storage
|
||||||
|
to be purely in-memory.
|
||||||
|
"""
|
||||||
|
migration_5 = Migration(
|
||||||
|
from_version=4,
|
||||||
|
to_version=5,
|
||||||
|
callback=Migration5Callback(logger=logger),
|
||||||
|
)
|
||||||
|
|
||||||
|
return migration_5
|
Loading…
Reference in New Issue
Block a user