Skip to content

Commit 8988539

Browse files
feat(db): add generated column for tags in db migration
1 parent 88c68e8 commit 8988539

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

invokeai/app/services/shared/sqlite/sqlite_util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_14 import build_migration_14
2020
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_15 import build_migration_15
2121
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_16 import build_migration_16
22+
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_17 import build_migration_17
2223
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_impl import SqliteMigrator
2324

2425

@@ -55,6 +56,7 @@ def init_db(config: InvokeAIAppConfig, logger: Logger, image_files: ImageFileSto
5556
migrator.register_migration(build_migration_14())
5657
migrator.register_migration(build_migration_15())
5758
migrator.register_migration(build_migration_16())
59+
migrator.register_migration(build_migration_17())
5860
migrator.run_migrations()
5961

6062
return db
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sqlite3
2+
3+
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_common import Migration
4+
5+
6+
class Migration17Callback:
7+
def __call__(self, cursor: sqlite3.Cursor) -> None:
8+
self._add_workflows_tags_col(cursor)
9+
10+
def _add_workflows_tags_col(self, cursor: sqlite3.Cursor) -> None:
11+
"""
12+
- Adds `tags` column to the workflow_library table. It is a generated column that extracts the tags from the
13+
workflow JSON.
14+
"""
15+
16+
cursor.execute(
17+
"ALTER TABLE workflow_library ADD COLUMN tags TEXT GENERATED ALWAYS AS (json_extract(workflow, '$.tags')) VIRTUAL;"
18+
)
19+
20+
21+
def build_migration_17() -> Migration:
22+
"""
23+
Build the migration from database version 16 to 17.
24+
25+
This migration does the following:
26+
- Adds `tags` column to the workflow_library table. It is a generated column that extracts the tags from the
27+
workflow JSON.
28+
"""
29+
migration_17 = Migration(
30+
from_version=16,
31+
to_version=17,
32+
callback=Migration17Callback(),
33+
)
34+
35+
return migration_17

0 commit comments

Comments
 (0)