Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

1.1 KB
Raw Blame
import sqlite3

from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_common import Migration


class Migration17Callback:
    def __call__(self, cursor: sqlite3.Cursor) -> None:
        self._add_workflows_tags_col(cursor)

    def _add_workflows_tags_col(self, cursor: sqlite3.Cursor) -> None:
        """
        - Adds `tags` column to the workflow_library table. It is a generated column that extracts the tags from the
            workflow JSON.
        """

        cursor.execute(
            "ALTER TABLE workflow_library ADD COLUMN tags TEXT GENERATED ALWAYS AS (json_extract(workflow, '$.tags')) VIRTUAL;"
        )


def build_migration_17() -> Migration:
    """
    Build the migration from database version 16 to 17.

    This migration does the following:
        - Adds `tags` column to the workflow_library table. It is a generated column that extracts the tags from the
            workflow JSON.
    """
    migration_17 = Migration(
        id="migration_17",
        depends_on="migration_16",
        from_version=16,
        to_version=17,
        callback=Migration17Callback(),
    )

    return migration_17