feat(memory): add protected memory config deletion with end-user safeguards
- Add force parameter to delete_config endpoint for controlled deletion of in-use configs - Implement MemoryConfigService.delete_config with protection against deleting default configs - Add validation to prevent deletion of configs with connected end-users unless force=True - Reorganize controller imports to remove duplicates and improve maintainability - Clean up unused database connection management code from memory_storage_controller - Add detailed docstring to delete_config endpoint explaining protection mechanisms - Update error handling with specific BizCode.RESOURCE_IN_USE for configs in active use - Add comprehensive logging for deletion attempts, warnings, and affected users - Refactor ConfigParamsDelete schema usage to use MemoryConfigService directly - Improve API response structure with affected_users count and force_required flag
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
from app.db import Base
|
||||
from sqlalchemy import BigInteger, Column, DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, String, Text
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.db import Base
|
||||
|
||||
|
||||
class EndUser(Base):
|
||||
__tablename__ = "end_users"
|
||||
@@ -21,7 +22,13 @@ class EndUser(Base):
|
||||
updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
|
||||
|
||||
# Memory config association - updated lazily during conversation
|
||||
memory_config_id = Column(Integer, ForeignKey("data_config.config_id"), nullable=True, index=True, comment="关联的记忆配置ID")
|
||||
memory_config_id = Column(
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("memory_config.config_id"),
|
||||
nullable=True,
|
||||
index=True,
|
||||
comment="关联的记忆配置ID"
|
||||
)
|
||||
|
||||
# 用户基本信息字段
|
||||
position = Column(String, nullable=True, comment="职位")
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import datetime
|
||||
from sqlalchemy import Column, String, Boolean, DateTime, Integer, Float
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, Float, Integer, String
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
|
||||
from app.db import Base
|
||||
|
||||
|
||||
@@ -38,6 +40,7 @@ class MemoryConfig(Base):
|
||||
|
||||
# 状态配置
|
||||
state = Column(Boolean, default=False, comment="配置使用状态")
|
||||
is_default = Column(Boolean, default=False, comment="是否为工作空间默认配置")
|
||||
|
||||
# 分块策略
|
||||
chunker_strategy = Column(String, default="RecursiveChunker", comment="分块策略")
|
||||
|
||||
Reference in New Issue
Block a user