From d9bcb26154d2eb92dba84e784dd32bc811c4c159 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 17 Apr 2026 07:59:33 +0000 Subject: [PATCH] fix: align index name between model and migration, drop unused import Use explicit Index() in __table_args__ matching the migration's 'memory_user_id_idx' name (consistent with chats.py / tags.py / chat_messages.py). Avoids autogenerate churn from SQLAlchemy's default ix_memory_user_id name. Also drops the unused sqlalchemy import from the migration. --- .../versions/a749ab2aa953_add_memory_user_id_index.py | 1 - backend/open_webui/models/memories.py | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/migrations/versions/a749ab2aa953_add_memory_user_id_index.py b/backend/open_webui/migrations/versions/a749ab2aa953_add_memory_user_id_index.py index 6a54d8d27b..254d49f7bf 100644 --- a/backend/open_webui/migrations/versions/a749ab2aa953_add_memory_user_id_index.py +++ b/backend/open_webui/migrations/versions/a749ab2aa953_add_memory_user_id_index.py @@ -7,7 +7,6 @@ Create Date: 2026-04-17 00:00:00.000000 """ from alembic import op -import sqlalchemy as sa revision = 'a749ab2aa953' down_revision = 'c1d2e3f4a5b6' diff --git a/backend/open_webui/models/memories.py b/backend/open_webui/models/memories.py index 1ec52eeb6a..5de250c1fb 100644 --- a/backend/open_webui/models/memories.py +++ b/backend/open_webui/models/memories.py @@ -6,7 +6,7 @@ from sqlalchemy import select, delete from sqlalchemy.ext.asyncio import AsyncSession from open_webui.internal.db import Base, get_async_db_context from pydantic import BaseModel, ConfigDict -from sqlalchemy import BigInteger, Column, String, Text +from sqlalchemy import BigInteger, Column, Index, String, Text #################### # Memory DB Schema @@ -19,11 +19,15 @@ class Memory(Base): __tablename__ = 'memory' id = Column(String, primary_key=True, unique=True) - user_id = Column(String, index=True) + user_id = Column(String) content = Column(Text) updated_at = Column(BigInteger) created_at = Column(BigInteger) + __table_args__ = ( + Index('memory_user_id_idx', 'user_id'), + ) + class MemoryModel(BaseModel): id: str