-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathmigration_28.py
More file actions
45 lines (33 loc) · 1.88 KB
/
migration_28.py
File metadata and controls
45 lines (33 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Migration 28: Add per-user workflow isolation columns to workflow_library.
This migration adds the database columns required for multiuser workflow isolation
to the workflow_library table:
- user_id: the owner of the workflow (defaults to 'system' for existing workflows)
- is_public: whether the workflow is shared with all users
"""
import sqlite3
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_common import Migration
class Migration28Callback:
"""Migration to add user_id and is_public to the workflow_library table."""
def __call__(self, cursor: sqlite3.Cursor) -> None:
self._update_workflow_library_table(cursor)
def _update_workflow_library_table(self, cursor: sqlite3.Cursor) -> None:
"""Add user_id and is_public columns to workflow_library table."""
cursor.execute("PRAGMA table_info(workflow_library);")
columns = [row[1] for row in cursor.fetchall()]
if "user_id" not in columns:
cursor.execute("ALTER TABLE workflow_library ADD COLUMN user_id TEXT DEFAULT 'system';")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_workflow_library_user_id ON workflow_library(user_id);")
if "is_public" not in columns:
cursor.execute("ALTER TABLE workflow_library ADD COLUMN is_public BOOLEAN NOT NULL DEFAULT FALSE;")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_workflow_library_is_public ON workflow_library(is_public);")
def build_migration_28() -> Migration:
"""Builds the migration object for migrating from version 27 to version 28.
This migration adds per-user workflow isolation to the workflow_library table:
- user_id column: identifies the owner of each workflow
- is_public column: controls whether a workflow is shared with all users
"""
return Migration(
from_version=27,
to_version=28,
callback=Migration28Callback(),
)