Skip to content

Commit

Permalink
Merge pull request #115 from UST-QuAntiL/fix/migration-sqlite
Browse files Browse the repository at this point in the history
Fix migration for sqlite
  • Loading branch information
PhilWun authored Dec 20, 2023
2 parents 05451b4 + 8955ebc commit 73b2b14
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""empty message
"""Initial migration.
Revision ID: ae51830d0cb5
Revises:
Expand Down
28 changes: 0 additions & 28 deletions migrations/versions/b889171b490f_.py

This file was deleted.

40 changes: 40 additions & 0 deletions migrations/versions/b889171b490f_id_to_key_datablob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Change id column in Table DataBlob to a key column for text based primary keys.
Revision ID: b889171b490f
Revises: a09e03db46a1
Create Date: 2023-11-09 12:33:37.697251
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "b889171b490f"
down_revision = "a09e03db46a1"
branch_labels = None
depends_on = None


def upgrade():
# drop and recreate table in cse some data is already present
# should not be the case before this migration
op.drop_table("DataBlob")
op.create_table(
"DataBlob",
sa.Column("plugin_id", sa.String(length=550), nullable=False, primary_key=True),
sa.Column("key", sa.String(500), primary_key=True),
sa.Column("value", sa.LargeBinary(), nullable=False),
sa.PrimaryKeyConstraint("plugin_id", "key", name=op.f("pk_DataBlob")),
)


def downgrade():
# drop new table and recreate old version
op.drop_table("DataBlob")
op.create_table(
"DataBlob",
sa.Column("id", sa.INTEGER(), nullable=False),
sa.Column("plugin_id", sa.String(length=550), nullable=False),
sa.Column("value", sa.LargeBinary(), nullable=False),
sa.PrimaryKeyConstraint("id", "plugin_id", name=op.f("pk_DataBlob")),
)
8 changes: 4 additions & 4 deletions qhana_plugin_runner/db/models/virtual_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
select,
)

from .mutable_json import JSON_LIKE, MutableJSON
from ..db import DB, DB_SIGNALS, REGISTRY
from ...util.plugins import plugin_identifier
from ..db import DB, DB_SIGNALS, REGISTRY
from .mutable_json import JSON_LIKE, MutableJSON

VIRTUAL_PLUGIN_CREATED = DB_SIGNALS.signal("virtual-plugin_created")
VIRTUAL_PLUGIN_REMOVED = DB_SIGNALS.signal("virtual-plugin_removed")
Expand Down Expand Up @@ -301,7 +301,7 @@ def get_value(cls, plugin_id: str, key: str, default: Any = ...) -> bytes:
KeyError: if the key was not found and no default value was provided
Returns:
bytes: the stored state value
bytes: the stored state value, or the default value
"""
q: Select = select(cls)
q = q.filter(cls.plugin_id == plugin_id, cls.key == key)
Expand All @@ -316,7 +316,7 @@ def get_value(cls, plugin_id: str, key: str, default: Any = ...) -> bytes:
@classmethod
def set_value(
cls, plugin_id: str, key: str, value: bytes, commit: bool = False
) -> bytes:
) -> Optional[bytes]:
"""Set state for a given key.
Args:
Expand Down

0 comments on commit 73b2b14

Please sign in to comment.