refac
This commit is contained in:
1 parent
793a43d9c4
commit
28bdcb063b
2 files changed
+38
-1
No files matched your search
+36
@@ -0,0 +1,36 @@
|
|||||||
|
"""Add memory (id, user_id) covering index
|
||||||
|
|
||||||
|
Revision ID: 55f1302ac17c
|
||||||
|
Revises: b0018471bbbe
|
||||||
|
Create Date: 2026-07-24 00:00:00.000000
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
|
||||||
|
revision: str = '55f1302ac17c'
|
||||||
|
down_revision: Union[str, None] = 'b0018471bbbe'
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = sa.inspect(conn)
|
||||||
|
indexes = {index['name'] for index in inspector.get_indexes('memory')}
|
||||||
|
|
||||||
|
if 'ix_memory_id_user_id' not in indexes:
|
||||||
|
op.create_index('ix_memory_id_user_id', 'memory', ['id', 'user_id'])
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = sa.inspect(conn)
|
||||||
|
indexes = {index['name'] for index in inspector.get_indexes('memory')}
|
||||||
|
|
||||||
|
if 'ix_memory_id_user_id' in indexes:
|
||||||
|
op.drop_index('ix_memory_id_user_id', table_name='memory')
|
||||||
@@ -8,7 +8,7 @@ from typing import Literal
|
|||||||
|
|
||||||
from open_webui.internal.db import Base, get_async_db_context
|
from open_webui.internal.db import Base, get_async_db_context
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
from sqlalchemy import JSON, BigInteger, Column, String, Text, delete, select
|
from sqlalchemy import JSON, BigInteger, Column, Index, String, Text, delete, select
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ class Memory(Base): # user memory store
|
|||||||
"""Stores user-created memory entries linked to a vector collection."""
|
"""Stores user-created memory entries linked to a vector collection."""
|
||||||
|
|
||||||
__tablename__ = 'memory'
|
__tablename__ = 'memory'
|
||||||
|
__table_args__ = (Index('ix_memory_id_user_id', 'id', 'user_id'),)
|
||||||
|
|
||||||
id = Column(String, primary_key=True, unique=True)
|
id = Column(String, primary_key=True, unique=True)
|
||||||
user_id = Column(String, index=True)
|
user_id = Column(String, index=True)
|
||||||
|
|||||||
Reference in new issue
Block a user